`args->opts` does not handle positional args after `--`

未关闭
#241 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

babashka/cli 的其他 Issue

查看 babashka/cli 的全部 Issue

相似的 Issue

更多 Clojure Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。