-
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
Nested Commands #24 #123
Conversation
Signed-off-by: Rudi Grinberg <[email protected]>
Thanks for your work @rgrinberg. I don't think I'll be able to have a look before the beginning of next year.
You mean showing the help ? I was thinking a bit about the default behaviour on In particular for when you use |
I had a quick look this morning, it's nice that it doesn't look too invasive. If I understand correctly you do not do anything special regarding docs except for listing One thing that nagged me while looking at this is: can we have Besides, I know Also I'm quite convinced that a group without the subcommand should error, not show the help. |
Let me give that a try.
Will do. Usually I do this at the end of the code review, to avoid intermediate changes to the docs. But it sounds like you agree with the API.
Sounds good to me. It will require us to change |
What would the error look like? |
I don't think that's needed, at the toplevel we need to keep the ability to have a default command. That default command could spit out the help. |
bb517f7
to
d0fd048
Compare
I added documentation to the Seems to be working well. |
Sorry I did not look at the details yet but I'm not sure I got that comment. Can we still get a default command if the toplevel sub-command is omitted ? Breaking this is a no-go. |
Yes, this behaviour is preserved. Only the omission of subcommands at lower levels results in an error. The re-implementation of |
Thanks ! This looks very good then. As I said it may take me a bit of time to merge (ping if it gets too long). But if further tweaks are needed I'll likely make them myself. Just one last thing, I noticed some strange stuttering in |
Np. We're in no hurry on the dune side.
Yes, I was meaning to ask about that. This issue is independent of my PR. |
Gentle ping @dbuenzli |
96064c2
to
b0f156d
Compare
This work is not being ignored :-) |
Signed-off-by: Rudi Grinberg <[email protected]>
to avoid regressions when eval_choice is implemented with groups Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
pass path correctly Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
b0f156d
to
d317645
Compare
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
| Error err -> | ||
let ei = Cmdliner_info.eval ~term:main ~main ~choices ~env in | ||
match choose_term (main_args, (fst main_f)) choices_f (remove_exec argv) with | ||
| Error (`No_args (path, choices)) -> |
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
or git remote
or opam 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 arguments args : string list
without the exec name:
- Let
sel : string list
be the list of all arguments ofargs
not prefixed by a-
and occuring before a potential--
. - If the
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 of args
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 parse bla.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
).
I'm thinking out loud and I'm not asking you @rgrinberg to look into what I'm saying, though if you wish you are welcome. But I tried to use the PR today for one subcommand in a project of mine already using I stopped because the change was too invasive as it required to change all other commands aswell to use the new grouping mecanism in order to be able to use I think the existence of all these
This means that the type for
should likely be extended to statically gather the tree of choices. This is all a bit hand-wavy but I have the impression that this is the way to go. Personally I hope I can get back to that problem at some point this summer. But I won't merge this PR before at least trying to explore that direction, if @rgrinberg or someone else wants to explore it before I manage to, most welcome. |
Daniel Bünzli ***@***.***> writes:
I think the existence of all these `eval_` function are the sign that
the choice problem is solved at the wrong level. The choice mecanism
needs to live in `'a Term.t`. In fact eventually there should be a
single `eval` function (and `eval_choices` kept for backward compat.)
and choice should be a combinator:
It's what I tried initially actually. I gave up with the impression at
that it would require a rewrite of a large chunk of cmdliner internals
to make it work this way. The approach that I took in this PR was much
less invasive in comparison.
should likely be extended to statically gather the tree of choices.
This is all a bit hand-wavy but I have the impression that this is the
way to go. Personally I hope I can get back to that problem at some
point this summer. But I won't merge this PR before at least trying to
explore that direction, if @rgrinberg or someone else wants to explore
it before I manage to, most welcome.
I probably won't have time either, but I agree that it's the way to go
if at all possible. Though personally, I did not find it very difficult
to refactor dune's cli to use the group based api in this PR. Even if it
is a little clunky.
|
On 11 May 2021 at 20:46:44, Rudi Grinberg ***@***.***) wrote:
It's what I tried initially actually.
Then we are on the right track!
I probably won't have time either, but I agree that it's the way to go
if at all possible. Though personally, I did not find it very difficult
to refactor dune's cli to use the group based api in this PR. Even if it
is a little clunky.
As discussed elsewhere I'm already not really happy with the current API so I'd rather not make it worse. Especially since we have the opportunity to add a feature while actually simplifying the API (eval_choice is no longer needed).
D
|
Something is now available on master. See the comment here for further details. Thanks @rgrinberg for your work. Despite that I'm not merging this it has not been unuseful and helped to get to the current design. |
Thanks for your hard work. I'll try master with dune and report how it works.
Rudi.
…On Jan 18, 2022, 2:02 PM -0700, Daniel Bünzli ***@***.***>, wrote:
Closed #123.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
This is my stab at #24. It seems to be feature complete with arbitrary command nesting, see
groups.t
for a demonstration.I'm thinking of dropping the default choice at the top level of nesting for consistency with subcommands. That would match dune's behavior of
$ dune
summoning the main help page.