-
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
Support for shell completion #187
base: master
Are you sure you want to change the base?
Conversation
a6c9982
to
41467e9
Compare
Thanks for getting your hands dirty with this @andreypopp. It is extremely appreciated. I won't have the time to look at this closely for some time. But since you seem to be in the mood, early feedback:
|
As it's only available since 4.13.
Thanks for the feedback! I've pushed few commits to address some of the feedback items and updated the More specifically:
I've added a
or to generate completion scripts to be distributed with cmdliner based programs if needed.
No environment variables are needed now. But the completion mode is activated
Noted. But I think this is a separate feature to be honest. For a good
Done. |
src/cmdliner.mli
Outdated
@@ -898,7 +898,9 @@ module Arg : sig | |||
|
|||
val info : | |||
?deprecated:string -> ?absent:string -> ?docs:string -> ?docv:string -> | |||
?doc:string -> ?env:Cmd.Env.info -> string list -> info | |||
?doc:string -> ?env:Cmd.Env.info -> | |||
?complete:[ `Complete_custom of unit -> (string * string) list | `Complete_dir | `Complete_file ] -> |
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.
We will need a proper type name for that. Also I don't think this belongs to info
it belongs to the 'a Arg.conv
type. E.g. if I use Arg.file
converter I shouldn't have to repeat `Complete_file
, (same for Arg.enum
).
Currently this type is not abstract but it has been scheduled to become since 2017. So probably it's now time to act and make 'a conv
into a proper abstract record.
Does that still fit your approach ?
5ddcc10
to
2161ee9
Compare
This doesn't affect how arguments are evaluated as each pos arg parse only looks at the own range of argv but it does affect which arg's completion is going to be used.
I've made the Then moved the completion specification to a converter:
Then there's another commit which changes the order we process pos args |
There's one other idea, I think, worth exploring. to make the completion That would allow to support cases where completion might depend on some
The code would look like:
|
This PR adds support for shell completion (as requested by #1).
Opening it early and as a draft to ask for feedback on the approach.
How it works, the gist
We define a shell completion protocol between a cmdliner-based program
and a shell.
On the shell side we expect to have a completion function which:
invokes a cmdliner-based program with a special completion token injected
into the argv line
interprets the output of the program completion and presents it to the user
We add a helper
cmdliner
tool (to be distributed with the library) which isused to generate shell completion scripts for a cmdliner-based program for
either bash or zsh (as requested).
How to test
In this PR I've configured dune to build example programs as executables, it's
convenient to have them on
$PATH
for testing, we also wantcmdliner
tool tobe available:
First we need to install completion handlers for our programs. Let's do that
for a few of example programs:
The supported values for
--shell
arebash
andzsh
as for now.Now I suggest to try the following completions (I'll paste the output I get as
well with
<TAB>
token showing the place where I've requested completions).Completion for top level options and subcommands:
Completion for options of a subcommand:
Completion of an option name:
Completion of an option value of enum type (see tail_ex.ml):
Completion of an argument value and option names:
Completion of an argument value (configured to filename completion):
Completion of only option names:
TODO
zsh
shellbash
shellfish
shelleval_peek_opts
--