amber-lang / amber-lang/amber

[Feature] Implement command line parser builtin

Aperta
#613 9 commenti 2 reazioni 1 assegnatario Rivendicata da @hdwalters Vedi su GitHub
enhancement
Lingua principale
Rust
Stelle
5.2k
Fork
145
Merge medio
5g 3h
PR unite (30g)
7

Descrizione

**Is your feature request related to a problem? Please describe.**
When writing Bash scripts taking command line options, I use `getopt` to preprocess the command line, and a `while` loop and `case` statement to handle individual options:

```
#!/usr/bin/env bash

# Parse command line or print help text.
script=""
files=()
title=""
items=()
depth=0
ultra=0
verbose=0
getopt=$(getopt --options=t:i:d:uv --longoptions=title:,items:,depth:,ultra,verbose,help -- "$@") || exit
eval set -- $getopt
while true; do
case "$1" in
-t|--title)
title="$2"
shift
shift
;;
-i|--items)
items+=("$2")
shift
shift
;;
-d|--depth)
depth="$2"
shift
shift
;;
-u|--ultra)
ultra=1
shift
;;
-v|--verbose)
verbose=1
shift
;;
--help)
cat <

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.