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

オープン
#241 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

  • #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分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

babashka/cli のほかの issue

babashka/cli の issue をすべて見る

似ている issue

Clojure の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。