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

stdlib: Fix argparse:format_help for sub-commands #8777

Merged

Conversation

jasewo
Copy link
Contributor

@jasewo jasewo commented Sep 3, 2024

When running this script:

#!/usr/bin/env escript

main(Args) ->
    argparse:run(Args, cli(), #{progname => cmd}).

cli() ->
    #{  
        commands => #{
            "sub-1" => #{
                commands => #{
                    "sub-1-1" => #{
                        arguments => [#{name => arg}],
                        help => "Help of sub-1-1 command"
                    }
                },
                help => "Help of sub-1 command"
            }
        },
        help => "Help of main command"
    }.

with these commands:

  • ./cmd
  • ./cmd sub-1
  • ./cmd sub-1 sub-1-1

after Usage section I'm always getting:

Help of main command

like:

$ ./cmd sub-1
error: cmd sub-1: subcommand expected
Usage:
  cmd sub-1 {sub-1-1}

Help of main command

Subcommands:
  sub-1-1 Help of sub-1-1 command

This commit fixes that so sub-commands help is used when possible, like:

$ ./cmd sub-1                                                                                                                                                                                
error: cmd sub-1: subcommand expected                                                                                                                                                        
Usage:                                                                                                                                                                                       
  cmd sub-1 {sub-1-1}                                                                                                                                                                        
                                                                                                                                                                                             
Help of sub-1 command                          

Subcommands:                                   
  sub-1-1 Help of sub-1-1 command              

Use sub-command's 'help' for formatting instead of command's one when
possible.
@CLAassistant
Copy link

CLAassistant commented Sep 3, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Sep 3, 2024

CT Test Results

    2 files     95 suites   56m 56s ⏱️
2 153 tests 2 105 ✅ 48 💤 0 ❌
2 512 runs  2 462 ✅ 50 💤 0 ❌

Results for commit 1aa91e7.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@max-au
Copy link
Contributor

max-au commented Sep 5, 2024

Good catch. It's pretty rare to have sub-sub commands, and I missed that it prints the generic help instead.

@garazdawi garazdawi self-assigned this Sep 5, 2024
@garazdawi garazdawi added team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI bug Issue is reported as a bug labels Sep 5, 2024
@garazdawi garazdawi merged commit 08fd5c3 into erlang:maint Sep 9, 2024
16 checks passed
@garazdawi
Copy link
Contributor

Thanks!

@garazdawi garazdawi added this to the OTP-27.1 milestone Sep 9, 2024
@jasewo
Copy link
Contributor Author

jasewo commented Sep 9, 2024

Thank you!

@jasewo jasewo deleted the stdlib/argparse-format_help-sub-commands-fix branch September 9, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants