Ignoring convention that `--` separate non-flag arguments in bash (apart from last `--` for fire flags)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 28.2k
- Fork
- 1.5k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/python-fire
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
google/python-fire#693 ·
-
Release 0.7.2? Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
google/python-fire#698 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
google/python-fire#672 · 5 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
google/python-fire#665 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
google/python-fire#659 · 1 bình luận ·
Tất cả issue của google/python-fire
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
learningequality/ricecooker#747 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
run-llama/llama_index#23199 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
KhronosGroup/glTF-Blender-IO#2769 ·