Added readme
This commit is contained in:
parent
243cdf9b7a
commit
6e6d0d35f2
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# arg - A simple command line argument parser
|
||||||
|
This is a simple tool with a simple job: figure out the value of a single
|
||||||
|
command line argument. Tools like `getopt` and `getopts` are much too
|
||||||
|
complicated. It's much nicer to be able to write shell scripts like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/sh
|
||||||
|
dir=`arg --dir "$@" || arg -d "$@" || echo "$HOME/Downloads"`
|
||||||
|
if arg -v "$@" || arg --verbose "$@"; then
|
||||||
|
echo "Downloading to $dir"
|
||||||
|
fi
|
||||||
|
cd $path && curl -O example.com/file.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
`arg -f ...`, `arg -flag ...`, or `arg --flag ...`. If `arg` finds the
|
||||||
|
given flag among the rest of the command line arguments, it will print
|
||||||
|
the flag's value (if any) and exit successfully, otherwise, it will
|
||||||
|
fail (exit status 1). The value may be of the form `--flag=value`,
|
||||||
|
`--flag value`, `-f value`. Single-letter flags will match when grouped
|
||||||
|
with other single letter flags, but will not have a value, i.e.
|
||||||
|
`arg -b -abc foo` will exit successfully without printing anything.
|
||||||
|
When using `arg` in a shell script, it is best to use quotes around `$@`,
|
||||||
|
as in `arg --foo "$@"`, so arguments with spaces will parse properly,
|
||||||
|
like `my_script.sh --flag "one two"`.
|
Loading…
Reference in New Issue
Block a user