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

Aperta
#11 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Ambito
cli

Direzione di ricerca

Inizia dal punto di ingresso cli/dispatch* mostrato nell’esempio e traccia come gli argomenti non definiti diventano voci nel risultato distribuito. Definisci il comportamento atteso di strict-mode per i flag sconosciuti, quindi aggiungi la copertura per il caso di errore di battitura e conferma che i flag validi continuino a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
Clojure
Stelle
56
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su Clojure

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.