Skip to content
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

Unable to use subword completion #49

Closed
Akendo opened this issue May 29, 2024 · 7 comments
Closed

Unable to use subword completion #49

Akendo opened this issue May 29, 2024 · 7 comments

Comments

@Akendo
Copy link

Akendo commented May 29, 2024

Hello 👋 ,

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
Copy link
Author

Akendo commented May 29, 2024

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.

@Akendo Akendo closed this as completed May 29, 2024
@adaszko
Copy link
Owner

adaszko commented May 29, 2024

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
Copy link
Author

Akendo commented May 29, 2024

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

@adaszko
Copy link
Owner

adaszko commented May 29, 2024

Hope you made it work. Cheers!

@adaszko
Copy link
Owner

adaszko commented May 30, 2024

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

adaszko added a commit that referenced this issue Jun 6, 2024
@adaszko
Copy link
Owner

adaszko commented Jun 6, 2024

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

adaszko added a commit that referenced this issue Jun 6, 2024
@Akendo
Copy link
Author

Akendo commented Jun 13, 2024

wow. Thanks a lot mate! Good thinking!

adaszko added a commit that referenced this issue Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants