-
Notifications
You must be signed in to change notification settings - Fork 56
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
Nested Commands #24 #123
Closed
Closed
Nested Commands #24 #123
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a5ff0e8
Add a function to make command aliases
rgrinberg e52080a
Fix warnings in darcs exmaple
rgrinberg 28268d6
Add tests for darcs_ex
rgrinberg 8e3e88d
prototype nested commands
rgrinberg d9808f1
add test for nested commands
rgrinberg d0d031b
enrich cmdliner_info term with group info
rgrinberg 2bed173
add help for main subcommand
rgrinberg 7f6c514
pass path & choices
rgrinberg a718d57
better error handling
rgrinberg 3cbe62c
more error handling
rgrinberg 63534f8
better help when no subcommand selected
rgrinberg a1a3819
Handle prefixes
rgrinberg 53bd9d3
No subcommand specified is an error
rgrinberg be75ba0
Use full term list for error message
rgrinberg dd64e4a
Document command groups
rgrinberg e29c474
Fix reversed term order
rgrinberg b47b44b
tweak error
rgrinberg 1552b34
fix eval_choice
rgrinberg ea8a842
simplify all the silly term handling
rgrinberg 3a4937f
implement eval_choice on top of group
rgrinberg 0b58b1e
Fix omission of main in path
rgrinberg 2faab86
default cmd test
rgrinberg d317645
fix displaying help
rgrinberg 2a2d70e
documentation testing
rgrinberg b4f5656
fix manpage for sub terms
rgrinberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
(lang dune 1.4) | ||
(name cmdliner) | ||
(lang dune 2.7) | ||
(name cmdliner) | ||
|
||
(cram enable) |
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
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
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
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.
Could this be configurable, so that the user can supply a default behavior if no subcommand is given? We'd need this for the behavior planned here: ocaml/dune#4367 (comment)
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.
IIRC. I'd rather not. See the discussion starting here.
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.
It seems common to have a natural default behavior for sub commands (see
git branch
orgit remote
oropam switch
etc.) (as you pointed out on linked conversation, in which, it seems, you were undecided at the time). It's also worth noting that @jeremiedimino, who had suggested the limitation, has actually requested precisely this behavior in the linked comment!I wonder if the seeming recurrence of this pattern might cause a reconsideration on this point? :)
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'm actually reconsidering.
I think in the general case selecting a nested command named
cmd : string list
should work as follows. Given command line argumentsargs : string list
without the exec name:sel : string list
be the list of all arguments ofargs
not prefixed by a-
and occuring before a potential--
.cmd
is a prefix ofsel
(and there's no longer command matchingsel
) thencmd
is the nested command to use.cmd
is then removed fromargs
and the result is parsed usingcmd
's term.This allows to have a default command at any level (if that command wants positional arguments they have to be specified after a
--
). Besides in contrast to the current behaviour for multi commands which requires the first argument ofargs
to be the name of the sub command. It allows to specify options before it, as long as those do not use the non-glued forms (like-o file
or--output file
).The end user can still end up being confused in many ways while refining cli invocations, but that's a bit in the dna of this poor interface medium and the behaviour seems not too hard to explain and understand.
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.
Of course that doesn't work :-) (e.g.
js_of_ocaml -o bla.js
breaks, it tries to parsebla.js
as a command).Even though I find that annoying, I think we are forced to require that no optional arguments occur before subcommand specifications (as was always the case in
cmdliner
).