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

argpars usage required args #7964

Closed
dgud opened this issue Dec 15, 2023 · 1 comment
Closed

argpars usage required args #7964

dgud opened this issue Dec 15, 2023 · 1 comment
Labels
help wanted Issue not worked on by OTP; help wanted from the community not a bug Issue is determined as not a bug by OTP team:VM Assigned to OTP team VM

Comments

@dgud
Copy link
Contributor

dgud commented Dec 15, 2023

Required arguments (options) are listed under Optional Arguments

I thought this was a bug and tried to solve that,
but then I discovered that the testcase test exactly that?

usage_required_args(Config) when is_list(Config) ->
    Cmd = #{commands => #{"test" => #{arguments => [#{name => required, required => true, long => "-req"}]}}},
    Expected = "Usage:\n  " ++ prog() ++ " test --req <required>\n\nOptional arguments:\n  --req required\n",
    ?assertEqual(Expected, unicode:characters_to_list(argparse:help(Cmd, #{command => ["test"]}))).

Shouldn't they be listed under arguments?

Any comments @max-au?

@dgud dgud added the bug Issue is reported as a bug label Dec 15, 2023
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Dec 18, 2023
@rickard-green rickard-green added the help wanted Issue not worked on by OTP; help wanted from the community label Dec 18, 2023
@max-au
Copy link
Contributor

max-au commented Dec 18, 2023

argparse has two types of arguments:

  • positional (those not prefixed with -)
  • optional (those prefixed with)

Parameter -long (or -short) is what makes the argument optional, hence --req is an optional argument.

Now, marking it as required does not change the argument type (it still stays optional). It only asks parser to throw an error when the option is not specified in the command line. This feature #{required => true is somewhat rare to use (and mainly needed to retrofit argparse for older software).

In other words, this isn't a bug, and works as expected.

@jhogberg jhogberg added the not a bug Issue is determined as not a bug by OTP label Dec 18, 2023
@jhogberg jhogberg removed the bug Issue is reported as a bug label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue not worked on by OTP; help wanted from the community not a bug Issue is determined as not a bug by OTP team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

5 participants