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

Hide subcommands unless command is selected? #438

Closed
synfinatic opened this issue Jul 11, 2024 · 7 comments
Closed

Hide subcommands unless command is selected? #438

synfinatic opened this issue Jul 11, 2024 · 7 comments

Comments

@synfinatic
Copy link

So I have some commands which have many sub-commands. When a user runs exec -h they see a lot of noise because each sub-command is listed. Is there a way to hide the sub-commands for command unless the user does exec command -h?

@synfinatic
Copy link
Author

example showing the ecs command which has many sub-commands I'd like to hide:

Usage: aws-sso <command> [flags]

Securely manage temporary AWS API Credentials issued via AWS SSO

Flags:
  -h, --help                               Show context-sensitive help.
  -b, --browser=STRING                     Path to browser to open URLs with ($AWS_SSO_BROWSER)
      --config="~/.aws-sso/config.yaml"    Config file ($AWS_SSO_CONFIG)
  -L, --level=STRING                       Logging level [error|warn|info|debug|trace] (default: warn)
      --lines                              Print line number in logs
  -u, --url-action=STRING                  How to handle URLs [clip|exec|open|print|printurl|granted-containers|open-url-in-container] (default: open)
  -S, --sso=STRING                         Override default AWS SSO Instance ($AWS_SSO)
      --sts-refresh                        Force refresh of STS Token Credentials
      --no-config-check                    Disable automatic ~/.aws/config updates
      --threads=INT                        Override number of threads for talking to AWS (default: 5)

Commands:
  cache [flags]
    Force reload of cached AWS SSO role info and config.yaml

  console [flags]
    Open AWS Console using specificed AWS role/profile

  credentials --profile=PROFILE,... [flags]
    Generate static AWS credentials for use with AWS CLI

  eval [flags]
    Print AWS environment vars for use with eval $(aws-sso eval ...)

  exec [<command> [<args> ...]] [flags]
    Execute command using specified IAM role in a new shell

  list [<fields> ...] [flags]
    List all accounts / roles (default command)

  login [flags]
    Login to an AWS Identity Center instance

  logout [flags]
    Logout from an AWS Identity Center instance and invalidate all credentials

  process [flags]
    Generate JSON for credential_process in ~/.aws/config

  tags [flags]
    List tags

  time [flags]
    Print how much time before current STS Token expires

  completions [flags]
    Manage shell completions

  config-profiles [flags]
    Update ~/.aws/config with AWS SSO profiles from the cache

  config [flags]
    Run the configuration wizard

  ecs auth [flags]
    Manage the ECS Server/AWS Client authentication

  ecs ssl delete
    Delete the current SSL certificate/private key

  ecs ssl print
    Print the current SSL certificate

  ecs ssl save --certificate=STRING [flags]
    Save a new SSL certificate/private key

  ecs server [flags]
    Run the ECS Server locally

  ecs docker start [flags]
    Start the ECS Server in a Docker container

  ecs docker stop [flags]
    Stop the ECS Server Docker container

  ecs list [flags]
    List profiles loaded in the ECS Server

  ecs load [flags]
    Load new IAM Role credentials into the ECS Server

  ecs unload [flags]
    Unload the current IAM Role credentials from the ECS Server

  ecs profile [flags]
    Get the current role profile name in the default slot

  version [flags]
    Print version and exit

@ccoVeille
Copy link

It would make sense

@alecthomas
Copy link
Owner

There are a whole bunch of options you can use to configure how the help is displayed. Play around and see if anything works for your use case. I typically use HelpOptions{Compact: true}

@alecthomas
Copy link
Owner

Barring that, you can actually write your own custom help formatter, though that is obviously significantly more work.

@ccoVeille
Copy link

ccoVeille commented Jul 11, 2024

Thanks for your feedback. It's indeed interesting.

Your "Read The F u…antastic Manual" was very polite. Maybe the kindest one I read for a while. I appreciate.😁

@synfinatic
Copy link
Author

Ah, well there ya go:

kong/help.go

Line 53 in a41b2e8

NoExpandSubcommands bool

thank you @alecthomas

@alecthomas
Copy link
Owner

You're welcome :)

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

No branches or pull requests

3 participants