lambdaisland / lambdaisland/cli
Q: Is there a way to fail if unknown flags/arguments are passed?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Clojure
- Sterne
- 56
- Forks
- 1
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne am im Beispiel gezeigten Einstiegspunkt cli/dispatch* und verfolge, wie undefinierte Argumente zu Einträgen im weitergeleiteten Ergebnis werden. Definiere das erwartete strict-mode-Verhalten für unbekannte Flags, füge dann Abdeckung für den Tippfehlerfall hinzu und bestätige, dass gültige Flags weiterhin funktionieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Bereich
- cli
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100