google / python-fire

Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.
Other
26.61k stars 1.43k forks source link

completion option for zsh #64

Open brucechou1983 opened 7 years ago

brucechou1983 commented 7 years ago

I'm using zsh 5.0.8 on OSX 10.11.6.

When I tried to run the generated completion bash for the basic example in README, I got the following error.

_complete-calculatorpy:4: unrecognized modifierC'`

I finally resolved this issue by replacing the : in the bash script with :.

An extra option for completion command will be helpful for zsh user.

dbieber commented 7 years ago

I finally resolved this issue by replacing the : in the bash script with :.

I don't follow -- you replaced a colon with a different colon? It would be great to have zsh support, but I haven't looked into supporting it yet. (I would also like a single completion script to work for all Fire CLIs, instead of having to generate one per CLI, but that's a bigger task than adding zsh support.)

pierrejeambrun commented 4 years ago

He changed the semi column with a semi column followed by a space. It seems to work but I have some weird autocompletion problem after the first argument, I don't know if this is the normal behavior though. (I cannot autocomplete other arguments or path after the first argument is selected)

llabusch93 commented 3 years ago

Hey guys,

is ZSH auto completion support planned?

Thanks for a followup.

loynoir commented 3 years ago

Ran into same issue.

unrecognized modifier `C'

Solved

SedMek commented 1 year ago

Thank you @loynoir for attempting to fix the issue, but it seems to me that your PR was closed, thus the problem of completion remains the same.

loynoir commented 1 year ago

@SedMek

https://github.com/google/python-fire/pull/320/commits/2faa993496bed4b7eb7298c3e01c1c377f3fd5f6

bukowa commented 1 year ago

@SedMek

  • Ah, I signed CLA, but later merged iln-sk changes for some extra types, who seems not signed CLA, and PR got blocked by CLA bot.
  • Plus I not using fire now, so I closed that blocked PR.

2faa993

Does not work for me :(

maximehk commented 8 months ago

The issue that triggered the unrecognized modifier error in ZSH should be fixed at head now. You can try and force re-installing the python-fire package.

pip install --upgrade --force-reinstall python-fire

GabLeRoux commented 7 months ago

I confirm the zsh completion works with zsh on latest commit d44d33d4ac9389854b046ca0270c112693b309e6 . To test it, this is what I did:

git clone git@github.com:google/python-fire.git
cd python-fire
python setup.py install

Here's a simple example

#!/usr/bin/env python

import fire

class Calculator:

    def add(self, a, b):
        return a + b

    def subtract(self, a, b):
        return a - b

    def multiply(self, a, b):
        return a * b

    def divide(self, a, b):
        return a / b

if __name__ == '__main__':
    fire.Fire(Calculator)

Named it calculator and added it to a folder which is in my PATH, then generated completions like this:

calculator -- --completion > calculator-completion
source calculator-completion

I confirm completions work fine:

CleanShot 2023-12-11 at 22 01 17@2x

CleanShot 2023-12-11 at 22 01 28@2x