argparse(1)

NAME
argparse - a command line parser for shell scripts

SYNOPSIS
argparse [args]

DESCRIPTION
argparse is a tool for parsing command lines. It is designed for using it within shell scripts.

You simple call the tool with the arguments of the script. Then the tool gets an string from stdin, which specifies the requested option.

The readed string from stdin must have a special format:

SHORT:name;LONG:name;TYPE:option_type

SHORT
    This option specifies the short name of the parameter. Eg.: h for -h

LONG
    This option specifies the long name og the parameter. Eg.: help for --help

    If the sepcified option was not found argparse will return an empty string.

TYPE
    This option specifies the type of the option. Eg.: string for a simple string

TYPES

flag
    argparse will return true if the option is set. This is the default setting if this parameter is not set.

bool
    If the option is set it will return the boolean value of the string followed the parameter.

    Eg.: --pretty_print true

    will return

    true

string
    A simple string option.

    Eg.: --infile text.txt

    will return

    text.txt

int The integer option.

double
    An double value.

arglist
    A list of strings.

    Eg.: --infiles file1.txt file2.txt file3.txt

    will return

    file1.txt file2.txt file3.txt

EXAMPLES
There are some examples how you can use argparse within shelscript. I'll demonstrate it with the bash

#------------- argparse-demo.sh --------------

#!/bin/sh

infiles=`argparse $* <<EOF

long:infile;short:if;type:arglist

EOF`

help=`argparse $* <<EOF

long:help;short:h;type:flag

EOF`

if test -z "$infiles"; then

 echo no infiles

else

 echo "the infiles: $infiles"

fi

if test -z "$help"; then

 echo no help needed

else

 echo "Usage: $0 [-h|--help] [-if|--infile] file1 file2 file3 ..."

fi

#------------- argparse-demo.sh --------------

Now the shellscript is as flexible at commandline parsing as real bis applications.

Test it:

$ ./argparse-demo.sh

no infiles

no help needed

$ ./argparse-demo.sh -if one two three -h

the infiles: one two three

Usage: ./argparse-demo.sh [-h|--help] [-if|--infile] file1 file2 file3 ...

NOTES
The tool is very flexible. If you doesn't specify a short option the long option will be taken and reverse.

The keywords SHORT, LONG, TYPE, string, int, double, bool, flag and arglist are incasesensitive.

BUGS
The command line option switch is hardcoded. - for short options and -- for the long options

AUTHOR
King Leo (Martin Oberzalek) <kingleo@gmx.at>