Added manpage

This commit is contained in:
Bruce Hill 2019-02-15 01:57:32 -08:00
parent fc2fefd049
commit 1d395a814a

66
arg.1 Normal file
View File

@ -0,0 +1,66 @@
.\" Manpage for arg.
.\" Contact bruce@bruce-hill.com to correct errors or typos.
.TH man 8 "14 February 2019" "1.0" "arg man page"
.SH NAME
arg \- A minimalist command line argument parser
.SH SYNOPSIS
.B arg
.I flag
.I ...
.SH DESCRIPTION
This is a handy tool for parsing out a single argument from a list of command
line arguments.
.SH INPUT
The first argument must be a flag (for example \fB-f\fR, \fB--foo\fR, or
\fBfoo\fR). This flag will be searched for among the remaining arguments.
.SH OUTPUT AND RETURN
If the flag is found, the program will exit successfully (exit status 0),
otherwise the program will fail (exit status 1). A flag is found if:
.RS 4
.HP 2
\fB-\fR one of the extra arguments is an exact match:
\fBarg --foo .. \fI--foo\fB [<value>]\fR
.HP 2
\fB-\fR one of the exact arguments begins with the flag followed by an '=' sign:
\fBarg --foo .. \fI--foo=\fB[<value>]\fR
.HP 2
\fB-\fR or the flag is a single dash followed by a single letter, and the letter
is found clustered with other letters after a single dash:
\fBarg -f .. -x\fIf\fBy\fR
If a value is found, the value is printed to stdout.
.RE
.SH EXAMPLES
The primary use case of this program is for shell scripting, as a much simpler
and easier to use alternative to getopt. Here are some simple shell script
examples:
.TP
.B
if foo=`arg --foo "$@"`; then echo "foo is '$foo'"; fi
If \fI--foo=value\fR or \fI--foo value\fR are in the arguments, the shell script
will print "foo is 'value'".
Note: it is important to put quotes around \fB$@\fR to ensure that
arguments with spaces get passed correctly.
.TP
.B
if arg -v "$@" || arg --verbose "$@"; then echo "Verbose!"; fi
Prints "Verbose!" if the shell script was run with either \fI-v\fR or \fI--verbose\fR.
.TP
.B
prefix=`arg prefix "$@" || echo "/usr/local"`
Sets prefix to the value of the \fIprefix\fR flag the user pased in, or if
no such flag was passed, \fI/usr/local\fR.
.SH AUTHOR
Bruce Hill (bruce@bruce-hill.com)