`args->opts` does not handle positional args after `--`
还没有人认领这个 Issue。
- #242 来自 @codebeige —— 已关闭,未合并
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 领域
- cli
调研方向
Start at parse-args in babashka/cli.cljc:908 and trace how -- separates positional arguments from the remaining args; compare that path with the existing :args->opts processing. Check the CLI tests for :args->opts and :restrict-args, then add coverage showing that post--- values are validated, coerced, and included in the option collection.
由索引模型根据 Issue 内容生成。
描述
version
0.12.92
platform
macos/arm64
problem
Positional arguments following -- are not handled by :args->opts and therefore stay unprocessed in :args without being added to the option's collection.
repro
(babashka.cli/parse-args ["foo" "bar" "--" "baz"]
{:args->opts [:positional-args]
:spec [[:positional-args {:coerce []}]]})
; => {:args ["baz"], :opts {:positional-args ["foo" "bar"]}}
With :restrict-args enabled, the following error is expected given the above behavior, but I think it is still be worth mentioning:
% bb -e '(babashka.cli/parse-args ["foo" "bar" "--" "baz"] {:args->opts [:positional-args] :restrict-args true :spec [[:positional-args {:coerce []}]]})'
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Unexpected argument: baz
Data: {:spec [[:positional-args {:coerce []}]], :type :org.babashka/cli, :cause :restrict-args, :msg "Unexpected argument: baz", :value "baz", :opts {:positional-args ["foo" "bar"]}}
Location: NO_SOURCE_PATH:1:1
----- Context ------------------------------------------------------------------
1: (babashka.cli/parse-args ["foo" "bar" "--" "baz"] {:args->opts [:positional-args] :restrict-args true :spec [[:positional-args {:coerce []}]]})
^--- Unexpected argument: baz
----- Stack trace --------------------------------------------------------------
babashka.cli/->error-fn/fn--24916 - <built-in>
babashka.cli/->error-fn/fn--24918 - <built-in>
babashka.cli/validate-opts - <built-in>
babashka.cli/parse-opts - <built-in>
babashka.cli/parse-args - babashka/cli.cljc:908:1
user - NO_SOURCE_PATH:1:1
expected behavior
Positional arguments following -- undergo the same processing (i.e. validation, coercion) as the ones before it, and everything is folded into the option's collection.
(babashka.cli/parse-args ["foo" "bar" "--" "baz"]
{:args->opts [:positional-args]
:spec [[:positional-args {:coerce []}]]})
; => {:opts {:positional-args ["foo" "bar" "baz"]}}
- 主要语言
- Clojure
- 星标
- 305
- 派生
- 24
- 平均合并
- 1 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
babashka/cli 的其他 Issue
-
Usage help: "Inherited options" heading might be confusing in some contexts可能已有人在做 @Sinkleberg 于 28 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
nextjournal/clerk#830 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
-
IOP tokens release blocker team qa team qa autotests WG adoption
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
izhangzhihao/intellij-rainbow-brackets#2903 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 67/100