Hide subcommands unless command is selected?
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?
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
It would make sense
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}
Barring that, you can actually write your own custom help formatter, though that is obviously significantly more work.
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.😁
Ah, well there ya go: https://github.com/alecthomas/kong/blob/a41b2e8f4ed34d80305fff68cf819f819c06ae7e/help.go#L53
thank you @alecthomas
You're welcome :)