-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
enable required for positionals #108
Comments
I'm not sure if this belongs here, or could be considered a separate issue: I'm using argparse with 3 (required) positional args and 1 optional arg. If you don't pass any args to the program, error is nil and program execution continues (and eventually causes errors when trying to access non existent files):
When I push this to a server for use by other users, most of them will naively execute it w/out any args nor even passing "-h" with the expectation that it will show them which arguments are required. In this scenario, the program just explodes: |
@ryansch80 Yes, that seems to be related, if I understand top post correctly As a workaround until this is fixed you could add a check of positional values and throw an error if they are not provided. |
@vsachs Thanks, I think we do need to enable
I think if positional is marked as required and there is no value available to fill it -- should throw an error. I would probably say that as per #108 (comment) it should be considered a bug rather than an enhancement. |
If we always throw an error when a required is unsatisfied, then if someone creates multiple sub-commands all of which have a required positional, the argparser will always error. There will be no way for one sub-command to "take precedence". I think that's not a good system but it's up for discussion of course.
I'll try to take a couple moments next week to fix this. I'm working on Nargs as well but I got pulled away from it. |
I see these issues and comments are older. Are you still maintaining this repo and accepting PRs? |
@Outragedpillow yes, although as you can see we're both easily distracted, I continuously think to myself I need to get back to this stuff I will try to do so this month or in october, sorry for the... hilariously long delays |
Positionals (added in 1.4) currently ignore the Required option. It should be supported, with these basic requirements:
-- This is necessary in order to avoid ambiguity of positional argument satisfaction: Say you have two positionals, the first is optional and the second is required. The user gives one value on the CLI. Which positional gets the value? Does the required positional get it IFF the optional has a default?
-- Do not throw an error if there are optional positionals on a parent command of the command which has had Required positionals added
Some discussion of the problem is warranted before coding begins. This may not be an exhaustive list of requirements.
The text was updated successfully, but these errors were encountered: