adaszko / complgen

Declarative bash/fish/zsh completions without writing shell scripts
Apache License 2.0
221 stars 7 forks source link

Unable to use subword completion #49

Closed Akendo closed 5 months ago

Akendo commented 5 months ago

Hello :wave: ,

firstly, thank you very much for this project. I love it. Unfortunately, I'm working on an auto-completion for a more complicated build process to make more sense of it. For this, I though using complgen might be a great idea. My usage file looks like this:

build [<OPTION>] <TARGET>;

<OPTION> ::= [--container-image=(localhost/builder|<IMAGES>)]                               "The default container image that is used."
           | [--container-engine=(docker| podman)]                                          "The software solution to implement a kernel namespace for the process." 
           | [--resolve-cname]                                                              "The platfrom, element or flag that should resolved for"
           | [--print-container-image]                                                      "Print the usaged container image."
           | [--kms]                                                                        "Set AWS environment variables to allow access to KMS." 
           | [--privileged]                                                                 "Set the container to have higher privileges." 
           | [--target <PATH> ]                                                             "The folder in which the artifices will be safed to." 
           ;

<TARGET> ::= <PLATFORM>[-(amd64|arm64)];

<ARCHITECTUR> ::= (amd64|arm64);

<PLATFORM@fish> ::= {{{ for feature in (ls -1 features);grep -E 'platform' features/$feature/info.yaml > /dev/null 2> /dev/null   && echo $feature;end  }}};
<PLATFORM@bash> ::= {{{ for feature in $(ls -1 features);do grep -qE 'platform' features/$feature/info.yaml 2> /dev/null  && echo $feature;done }}};
<IMAGES> ::= {{{ podman images -q }}};

#<PLATFORM>[-<ELEMENT>...] [-<FLAGS>..]-[<ARCHITECTUR>][-<TIME>];

The key problem I'm having is the following:

./build kvm- TAB

I want to mimic the following string, as an example: ./build kvm-python_readonly_dev-amd64-today

Currently, I autocomplete the platform, AWS or KVM here the options is working likewise, but I can't add anything that follows. I know that the dash is already breaking the fish completion, but I though building for bash first. I'm not sure what I'm doing wrong at the time, or does the dash break here more?

Not only that, but I think it should look like this later on:

<TARGET> ::= <PLATFORM>[-<ELEMENT>...] [_<FLAGS>...]-[<ARCHITECTUR>][-<TIME>];

I'm using Archlinux with the version 0.1.8-1 of comlgen from pacman. bash has Version 5.2.26(1)-release and fish has version 3.7.1.

Any help is appreciated!

And once more thank you for the the great work here.

Akendo commented 5 months ago

After reading your documentation, I stumbled across this:

{{{ ... }}} is only allowed at the tail position within subwords to avoid ambiguities:

I guess my problem is using this more than once. Thank anyway.

adaszko commented 5 months ago

Hi. Take a look at the Limitations section in the README. External commands can only appear at a tail position in a word to avoid ambiguities. If you're not getting any warnings, I should add one. I'm on mobile so it's awkward to type but you should be able to move -amd64/-arm64 suffix into to the shells command output and make it work.

Akendo commented 5 months ago

Thanks, mate, I just learned that as well. But much appreciate that you take the time to write here!

adaszko commented 5 months ago

Hope you made it work. Cheers!

adaszko commented 5 months ago

A question though: didn't you get a warning/error from complgen? I thought I had added it.

adaszko commented 4 months ago

Turns out there was a bug, and the .usage file above didn't generate an error message where it should have. I minimized it to:

build <PLATFORM>[-(amd64|arm64)];
<PLATFORM> ::= {{{ echo foo }}};

and now it produces:

% complgen check build.usage
0:6:error: External commands within subwords are only allowed at tail position to prevent ambiguities in matching
  |
0 | build <PLATFORM>[-(amd64|arm64)];
  |       ^^^^^^^^^^
  |
  = help: try to include the suffix in the external command output itself
Akendo commented 4 months ago

wow. Thanks a lot mate! Good thinking!