Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to hide aliases from root help commands list #888

Closed
devdumpling opened this issue May 18, 2022 · 2 comments · Fixed by oclif/core#819
Closed

Option to hide aliases from root help commands list #888

devdumpling opened this issue May 18, 2022 · 2 comments · Fixed by oclif/core#819

Comments

@devdumpling
Copy link

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

Running [bin] or [bin] help gives the root help for the CLI, including the list of all available commands. This is great for discovering everything that's available. However, my project supports many aliases, and those are cluttering the list making it harder to see what's available at a glance. It would be nice if there was a quick way to hide aliases from showing up in the root help.

I'm new to oclif and was trying to get this to work with the custom Help classes. Still digging there, so might find a cleaner solution but flagging it as a nice-to-have.

What is the expected behavior?

Passing some kind of hideAliasesFromRoot option to a command (or at a higher level config) hides command alias from rootHelp.

@shazron
Copy link
Contributor

shazron commented Jul 27, 2022

Related #925

@motabass
Copy link

motabass commented Jan 4, 2023

I also tried CustomHelp class approach and finally found a pretty good solution. I mostly just copied the implementation from the default Help class from oclif and added a filter + aliases at the end of the summary:

import { Help } from '@oclif/core';
import * as Interfaces from '@oclif/core/lib/interfaces';

export default class CustomHelp extends Help {
  formatCommands(commands: Interfaces.Command[]): string {
    if (commands.length === 0) return '';

    const body = this.renderList(
      commands
        // if aliases do not contain the current command's id it is the "main" command
        .filter((c) => !c.aliases.some((a) => a === c.id))
        .map((c) => {
          if (this.config.topicSeparator !== ':') c.id = c.id.replace(/:/g, this.config.topicSeparator);
          // Add aliases at the end of summary
          const summary = c.aliases.length > 0 ? `${this.summary(c)} (ALIASES: ${c.aliases.join(', ')})` : this.summary(c);
          return [c.id, summary];
        }),
      {
        spacer: '\n',
        stripAnsi: this.opts.stripAnsi,
        indentation: 2
      }
    );

    return this.section('COMMANDS', body);
  }
}

maybe this helps for now. Though i would also prefer a simple flag for the default Help class to enable such a Behaviour. Should be fairly easy to implement based on the example i provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants