Q: Is there a way to fail if unknown flags/arguments are passed?

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

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
领域
cli

调研方向

从示例中展示的 cli/dispatch* 入口点开始,跟踪未定义参数如何成为分派结果中的条目。定义 strict-mode 下对未知 flag 的预期行为,然后为拼写错误的情况添加覆盖测试,并确认有效 flag 仍然有效。

由索引模型根据 Issue 内容生成。

描述

Hi,

If the user passes an undefined flag is there a way to fail the cli/dispatch?

I assume that is a design choice to accept flags which have not been defined, but in some cases might be risky if fore example someone has a typo in a flag.

For example look at the following (contrived) example:

;; this command deletes the given argument
(def delete identity)

(cli/dispatch*
 {:command #'delete
  :flags ["-v, --verbose" "Increases verbosity"
          "--dry-run"     "Simulate but do not action"
          "--input FILE" "Specify the input file/folder"
          "--env=<dev|prod|test>" {:doc "Select an environment" :default "prod"}]}
;; typo in --dryrun (the correct should be --dry-run)
 ["--input" "all-my-data" "--dryrun"])

;; => {:lambdaisland.cli/sources
;;     {:env "--env=<dev|prod|test> (default value)",
;;      :input "--input command line flag"},
;;     :env "prod",
;;     :lambdaisland.cli/argv [],
;;     :input "all-my-data",
;;     :dryrun 1}

In this example the user might thing that he provided the --dryrun argument, the dispatcher will just dispatch as a new flag ignoring the fact that it was an unintentional mistake and because delete doesn't see the flag :dry-run true it will perform the actual delete.

Is there a way to add a :strict-mode true and fail on undefined flags?

主要语言
Clojure
星标
56
派生
1
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

把新 issue 发到你的邮箱

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