Auxilium Logo

auxilium.sh

POSIX Shell Argument Parsing Library

Features

Easy Argument Definition

Add arguments with long names (--arg) and short options (-a) in a simple, intuitive way.

Multiple Argument Types

Support for strings, boolean flags, positional arguments, and subcommands.

Auto Help Generation

Automatically generate comprehensive --help messages with descriptions and usage.

Shell Completion

Generate autocompletion scripts for Bash and Zsh shells.

POSIX Compatible

Works across different shells (bash, zsh, dash, ksh) for maximum portability.

Choice Validation

Validate argument values.

Installation

Installation
$ # Download and install auxilium.sh
$ sudo mkdir -p /usr/local/lib/auxilium
$ sudo cp auxilium.sh /usr/local/lib/auxilium/

                        

Usage

Basic Usage
#!/bin/sh
# Source the library
. /usr/local/lib/auxilium/auxilium.sh

# Initialize
auxilium_init "myapp" -m "My application description"

# Add arguments
auxilium_add "verbose" -s v -t opt -m "Enable verbose mode"
auxilium_add "config" -s c -d "/etc/app.conf" -m "Config file"
auxilium_add "format" -l "json|xml|yaml" -m "Output format"

# Parse arguments
auxilium_parse "$@"

# Use parsed values
echo "Config: $AUXILIUM_ARG_CONFIG"
[ "$AUXILIUM_ARG_VERBOSE" = "1" ] && echo "Verbose mode"

# Cleanup
auxilium_close

Examples

Help Output
Description:
    My application description

Usage: myapp [-h|--help] [-v|--verbose] [-c|--config CONFIG] [--format FORMAT]

Optional Arguments:
    -h|--help                      This help message
    -v|--verbose                   Enable verbose mode
    -c|--config CONFIG             Config file
                                   Default: /etc/app.conf
    --format FORMAT                Output format
                                   Choice: json|xml|yaml

auxilium.sh

Bibliothèque POSIX pour Parser les Arguments Shell

Fonctionnalités

Définition d'Arguments Facile

Ajoutez des arguments avec des noms longs (--arg) et des options courtes (-a) facilement.

Types d'Arguments Multiples

Support des chaînes, booléens, arguments positionnels et sous-commandes.

Génération d'Aide Automatique

Génère automatiquement des messages --help complets avec descriptions et usage.

Autocomplétion Shell

Génère des scripts d'autocomplétion pour les shells Bash et Zsh.

Compatible POSIX

Fonctionne sur différents shells (bash, zsh, dash, ksh) pour une portabilité maximale.

Validation de Choix

Valide les valeurs d'arguments.

$ ./installer.sh

Installation
$ # Télécharger et installer auxilium.sh
$ sudo mkdir -p /usr/local/lib/auxilium
$ sudo cp auxilium.sh /usr/local/lib/auxilium/
                        

$ cat utilisation.sh

Utilisation de Base
#!/bin/sh
# Sourcer la bibliothèque
. /usr/local/lib/auxilium/auxilium.sh

# Initialiser
auxilium_init "monapp" -m "Description de mon application"

# Ajouter des arguments
auxilium_add "verbose" -s v -t opt -m "Activer le mode verbeux"
auxilium_add "config" -s c -d "/etc/app.conf" -m "Fichier de config"
auxilium_add "format" -l "json|xml|yaml" -m "Format de sortie"

# Parser les arguments
auxilium_parse "$@"

# Utiliser les valeurs parsées
echo "Config: $AUXILIUM_ARG_CONFIG"
[ "$AUXILIUM_ARG_VERBOSE" = "1" ] && echo "Mode verbeux"

# Nettoyage
auxilium_close

$ ./usr/bin/auxilium_test --help

Sortie d'Aide
≥ /usr/bin/auxilium_test --help

Example code:
    . /usr/share/auxilium/auxilium.sh

    _opt_function(){
        echo "Bool function: --help "
    }

    _pos_function(){
        _ARG_NAME=--help
        shift
        echo "POS function:  --help"
    }

    auxilium_init auxilium_test "Test ARGS PARSE"
    auxilium_add opt -s b -t opt -c _opt_function -m 'Bool'
    auxilium_add string -s s -d 'asd'  -m 'This is a long String\nFor test this help message' 
    auxilium_add POS2 -t positional -m 'Positional2' -n * -c _pos_function


    auxilium_parse ${@}
    echo "OPT: "
    echo "STRING: "
    echo "POS2: "

    auxilium_usage

Output:

Description:                                               
   Test ARGS PARSE

Usage: auxilium_test [-h|--help ] [--sh_completion SH_COMPLETION] [-b|--opt ] [-s|--string STRING] 

Optionals Arguments:
   -h|--help 
                                  This help message
   --sh_completion SH_COMPLETION  Choice: bash|zsh
                                  Generate shell completion script
   -b|--opt 
                                  Bool
   -s|--string STRING             Default: default
                                  This is a long String
                                  For test this help message

Positional Argument:
   POS2...
                                  Positional2