-
Notifications
You must be signed in to change notification settings - Fork 19
Representing Dynamic Arguments #6
I really like this initiative.
One of the things I went deep into a rabbit hole last year with was around trying to build a CLI tool, and have it produce its own completion scripts in "the best possible way" (this was where I went wrong 😅 ).
I was able to get pretty much most of the way there with a tool called complgen which required its own grammar, but could then generate me the scripts I wanted for various shells (no pwsh though). One of the killer features is its ability to specify something to the effect that "this argument is a string, and you can get a list of completions by running this command", which gets very meta, but allows for a really powerful experience.
Would it be possible for the specification to be able to capture this sort of functionality? So to say it again, it would be some metadata to describe how to fetch completions, which would support running an executable (typically itself).
I think @baronfel has done some work in the space for the dotnet cli, so pinging him to see if he has any thoughts.
All reactions
-
❤️ 2
Replies: 2 comments 2 replies
I think it would be possible to capture this kind of functionality within the spec, but I'm not sure how 😅.
I haven't thought about this scenario before, but it shouldn't be impossible. Do you have any initial thoughts about how this could be done?
All reactions
Here's what we did for the dotnet CLI's static completion script generation. @slang25 is right that we needed a sort of 'marker' to signal to each of the shell-specific implementations that "you need to go run a command here to get more data". The part that we're missing from the overall implementation, and the part I need to solve before spinning the entire csproj off as a library built on top of S.CL, is figuring out a good way to tell the shell-specific generators what that command to run should be. Right now it's hard coded to 'dotnet complete', but you could imagine any number of options for individual CLIs fitting here. It's also possible that this library might auto-include a default completions command similar to 'dotnet complete' so that commands don't need to rely on 'dotnet-suggest' being installed, etc.
All reactions
I think a reasonable approach would be to restrict "call this to get list of permissible values" to commands from the same spec. After all, we can assume little about the runtime environment besides the program at hand being available.
Sketching for docker image rm:
"commands": [ { "name": "rm", "arguments": [ { "name": "IMAGE", "description": "The image ID to delete", "required": true, "acceptedValues": { "command": [ "image", "ls", "--quiet" ] } } ], } ]
as opposed to acceptedValues.enum: [ "a", "b", "c" ] (which would replace the current acceptedValues: [ "a", "b", "c" ].
[docker] image ls would have to be a (sub)command from the same spec, with option --quiet.
This should enable
- validation of the spec ("is that command valid itself?"),
- generation of completion scripts ("call the given command and use its output"), and
- code generation ("call the method that implements that command").
(I'm fully aware that this sketch wouldn't be good enough for docker completions; we'd want to see tags, not IDs! Well, I'll say this: a standard like the above might actually force developers to provide easy commands to get scriptable output ...)
All reactions
Just to add some specific use cases that occur every day for me:
docker image rm <caret>-- should auto-complete the list of currently present imagesmise install <caret>-- should auto-complete the list of available tools and versions (as per the registry cache)helix <caret>-- should auto-complete directories and (text) filesevince <caret>-- should auto-complete directories and (supported) filesrm <cared>-- should auto-complete (executable?) directories and (writeable?) files
Maybe it's possible to cover file-based completions in a general way (using filters for permissions, extensions, mime types?), but it may also not be worth doing if programmatic ways are supported. (Unless and until common patterns have emerged through usage, that is.)
All reactions
-
👍 1