#!/usr/bin/env bash # -*- tab-width: 4; encoding: utf-8; -*- # ######### # License: # # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # Version 2, December 2004 # # Copyright (C) 2004 Sam Hocevar # # Everyone is permitted to copy and distribute verbatim or modified # copies of this license document, and changing it is allowed as long # as the name is changed. # # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION # # 0. You just DO WHAT THE FUCK YOU WANT TO. # ######### # ## @file ## @author Damien Nadé ## @copyright WTFPLv2 ## @version 1.8 ## @brief Bash Argsparse Library ## @details ## @par URL ## https://github.com/Anvil/bash-argsparse @n ## ## @par Purpose ## ## To replace the option-parsing and usage-describing functions ## commonly rewritten in all scripts. ## ## @note ## This library is implemented for bash version 4. Prior versions of ## bash will fail at interpreting that code. ## @note ## The extglob shell option will be enabled and posix mode will be ## disabled when loading the library. Changing those settings ## afterwards will make the library execution fail. ## ## @par Usage ## Use the argsparse_use_option() function to declare your options with ## their single letter counterparts, along with their description. ## ## @par ## The argsparse_use_option() syntax is: ## ## @code ## argsparse_use_option "optstring" "option description string" \ ## [ "property" ... ] [ "optional default value" ] ## @endcode ## ## ## @par ## An "optstring" is of the form "som=estring:". This would declare a ## long option named somestring. The ending ":" is optional and, if ## present, means the long option expects a value on the command ## line. The "=" char is also optional and means the immediatly ## following letter is the short single-letter equivalent option of ## --something. ## ## @par ## The "something" string must only contains ASCII ## letters/numbers/dash/underscore characters. ## ## @note ## What is referred later as "option" or "option name" (or even "long ## option name") is the optstring without the ':' and '=' characters. ## ## ## ## @par Options may have properties. ## ## Properties are set either at option declarations through the ## argsparse_use_option() function, or using the ## argsparse_set_option_property() function ## ## The currently supported properties are: ## ## - "hidden" @n ## An hidden option will not be shown in usage. ## ## - "mandatory" @n ## An option marked as mandatory is required on the command line. If ## a mandatory option is omited by the user, usage() will be ## triggered by argsparse_parse_options(). ## ## - "value" @n ## On the command line, the option will require a value. ## Same effect if you end your optstring with a ':' char. ## ## - "default:" @n ## The default value for the option. ## ## - "short:" @n ## The short single-letter equivalent of the option. ## ## - "type:" @n ## Give a type to the option value. User input value will be checked ## against built-in type verifications _or_ the ## "check_type_" function. You cannot override a built-in ## type. Built-in types are: ## - file ## - directory ## - pipe ## - terminal ## - socket ## - link ## - char ## - unsignedint ## - uint ## - integer ## - int ## - hexa ## - ipv4 ## - ipv6 ## - ip ## - hostname ## - host ## - portnumber ## - port ## - username ## - group ## - date ## . ## ## - "exclude: