crazy-complete / crazy-complete

Generate shell auto completion files
GNU General Public License v3.0
2 stars 1 forks source link

Feature request: mutualy exclusive options #3

Open meator opened 11 hours ago

meator commented 11 hours ago

Hey, I am a maintainer of j4-dmenu-desktop and I have been seriously considering switching to your project for providing completions. I must say that your project is awesome and has exceeded my expectations. It's nice to see that command is available as a completion variant. Your YAML format is much nicer to work with than competition's.

I would like to request mutaly exclusive options. j4-dmenu-desktop will have two new flags in its upcoming release: --desktop-file-quirks and --strict-parsing. These two flags cannot be specified together.

j4-dmenu-desktop already has hand written completion scripts for Bash, Fish and ZSH. This is how it's handled in ZSH right now:

    '(--strict-parsing)--desktop-file-quirks=[set compatibility modes]:flags:_desktop_file_quirks_values'
    '(--desktop-file-quirks)--strict-parsing[enable strict desktop file parsing]'

This is how it's handled in Fish right now:

complete -c j4-dmenu-desktop -x       -l desktop-file-quirks -n 'not __contains_opt strict-parsing' -a "(__complete_list , __desktop_file_quirks_list)" -d "Enable nonconformant desktop file parsing quirks"
complete -c j4-dmenu-desktop          -l strict-parsing -n 'not __contains_opt desktop-file-quirks' -d "Enable strict desktop file parsing"

The Fish completion is a bit more janky, it depends on undocumented and therefore unstable builtin completion functions. I am talking about the __fish_contains_opt and __fish_complete_list. I have copied the function definitions from Fish's latest release into my completion script to maintain stability.

This is the approach I was recommended by the official Fish Matrix channel.

I haven't implemented mutal exclusivity in Bash.

meator commented 10 hours ago

I don't have extensive knowledge of Bash's, Fish's and ZSH's completion scripts (although I know a bit about ZSH's), but I'd be willing to contribute/collaborate if there is interest. If you find these features worthwhile to implement, I'll probably leave it up to you (because I assume that your knowledge of this matter is greater than mine @braph), but I'd be willing to contribute otherwise. I can also test the changes on j4-dmenu-desktop.

braph commented 7 hours ago

I'm happy to inform you that mutually exclusive options are already supported by crazy-complete! You can achieve this by using the group field, which is part of the option dictionary. For each mutually exclusive option, simply assign the same group value, and the program will ensure that these options cannot be used together. You can have a look at https://github.com/crazy-complete/crazy-complete/blob/main/completions/pylint/pylint.yaml to see a real life example.