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
Initial implementation of positional arguments #102
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
70c9186
Initial prototype of positional arguments
vsachs 3d0a35c
Unit tests and minor changes
vsachs 7c3906d
Fail command.addArg for disallowed positional types
vsachs 1e3af52
Remove incorrect comment
vsachs 24b09dd
Add examples and info to the README
vsachs b53ab63
Refactor code so that Options.Positional is now private field set in …
vsachs 10d85f1
Augment tests to cover new functions better
vsachs c62e945
Add TestPos8
akamensky 1e2e679
Add tests for parse ordering issues
vsachs c1c45f5
Utilize two-stage parsing with positionals subsequent to flags
vsachs f965350
Implement breadth-first positional parsing. Enable positional Option.…
vsachs c2b22b8
Add tests for empty positional and for positional defaults
akamensky File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, interesting, while
Default == nil
makes sense (positional either provided or it is not), I am not so sure aboutRequired == true
.Assuming for a sub-command tree we defined 5 positionals:
progname cmd1 cmd2 prognamePositional1 prognamePositional2 cmd1Positional1 cmd1Positional2 cmd2Positional
, and input provided on CLIprogname cmd1 cmd2 somestr1 somestr2 somestr3
, the only way we can match positional arguments is in the order they provided. Hence:prognamePositional1 == somestr1
prognamePositional2 == somestr2
cmd1Positional1 == somestr3
cmd1Positional2 == nil
cmd2Positional == nil
Which would make it possible to define "optional" positionals, as in -- if it was not provided, it is not set to any value, meantime any that provided will be matched to their corresponding positional in exactly same order (that is in example above
prognamePositional1
should always be matched tosomestr1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I can allow this relatively easily but it's going to open a can of worms. What if the only optional positionals are actually prognamePositional1 and prognamePositional2? We can't distinguish which positionals the user is trying to fill (unless we actually allow naming of the positionals on the CLI, which... basically defeats the whole point), so we will still end up with the same result above except that the last two are required and nil, giving us an error. Effectively they are all required in this scenario.
Do we want to require that any optional positionals be at the tail end of added arguments? If so this has the implication: