Ignoring convention that `--` separate non-flag arguments in bash (apart from last `--` for fire flags)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
Start by reproducing the minimal test.py example and then inspect fire/core.py around line 376, where argument parsing is identified. Trace how multiple -- arguments are handled. Done means the earlier -- causes remaining arguments, including --flag 3, to be treated positionally while the final -- remains handled as shown in the expected output.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Beyond the fact that fire uses the last -- to separate flag argument from command arguments, it seems that previous -- are not parsed correctly. At least according to the common convention that a double dash ( -- ) is used in most Bash built-in commands and many other commands to signify the end of command options, after which only positional ("non-option") arguments are accepted (source).
I would like to use this to pass some other commands to a fire command, without the flags targeted to the extra command being parsed by fire. Here is a minimal example test.py:
import fire
def foo(*args: str, flag: int = 2) -> None:
print(f"{args=} {flag=}")
fire.Fire(foo)
Current behavior:
$ python test.py -- other args 1 2 --flag 3 --
args=('args', 1, 2) flag=3
ERROR: Could not consume arg: --
Usage: test.py -- other args 1 2 -
For detailed information on this command, run:
test.py -- other args 1 2 - --help
Expected behavior:
python test.py -- other args 1 2 --flag 3 --
args=('args', 1, 2, "--flag", 3) flag=2
Would you be fine with updating the parsing rules in https://github.com/google/python-fire/blob/6cf45c663075c96b20dd0dfa733c2374545a4ad6/fire/core.py#L376 to consider all remaining args as positional arguments if it encounter a -- ? I could work on a PR if there is no major blocker.
- Lingua principale
- Python
- Stelle
- 28.2k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/python-fire
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
google/python-fire#693 ·
-
Release 0.7.2? Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
google/python-fire#698 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
google/python-fire#672 · 5 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
google/python-fire#665 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
google/python-fire#659 · 1 commento ·
Tutte le issue di google/python-fire
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
learningequality/ricecooker#747 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
run-llama/llama_index#23199 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
KhronosGroup/glTF-Blender-IO#2769 ·