├── debian ├── compat ├── docs ├── rules ├── control └── changelog ├── .gitignore ├── .travis.yml ├── COPYING ├── tutorial ├── 5-custom-types ├── 0-completion ├── 7-value-checking ├── 3-cumulative-options ├── 2-values ├── 9-misc ├── 8-setting-hook ├── 1-basics ├── 6-properties └── 4-types ├── bash-argsparse.spec ├── README.md ├── doxygen-bash.sed ├── argsparse-completion.sh ├── unittest └── argsparse.sh /debian/compat: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | html 2 | tutorial 3 | README.md 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | html 3 | latex 4 | debian/bash-argsparse* 5 | debian/files 6 | debian/debhelper-build-stamp 7 | unittest.log 8 | \#* 9 | .\#* 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | include: 3 | - os: linux 4 | dist: precise 5 | - os: linux 6 | dist: trusty 7 | - os: linux 8 | dist: xenial 9 | 10 | language: bash 11 | 12 | script: 13 | - ./unittest 14 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | override_dh_install: 4 | dh_install 5 | rm -R debian/bash-argsparse 6 | mkdir -p debian/bash-argsparse/usr/bin 7 | for file in argsparse argsparse-completion; do \ 8 | install -m 0755 "$$file.sh" debian/bash-argsparse/usr/bin ; \ 9 | ln -s "$$file.sh" debian/bash-argsparse/usr/bin/"$$file" ; \ 10 | done 11 | 12 | build: 13 | dh build 14 | doxygen 15 | 16 | %: 17 | dh $@ 18 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: bash-argsparse 2 | Section: libs 3 | Priority: optional 4 | Maintainer: Damien Nade 5 | Build-Depends: debhelper (>= 7.0.50), doxygen 6 | 7 | Package: bash-argsparse 8 | Architecture: all 9 | Depends: bash (>= 4), util-linux 10 | Homepage: https://github.com/Anvil/bash-argsparse 11 | Description: An high level argument parsing library for bash 12 | An high level argument parsing library for bash. 13 | . 14 | The purpose is to replace the option-parsing and usage-describing 15 | functions commonly rewritten in all scripts. 16 | . 17 | This library is implemented for bash version 4. Prior versions of 18 | bash will fail at interpreting that code. 19 | . 20 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | bash-argsparse (1.8) unstable; urgency=low 2 | 3 | * Version 1.8 4 | 5 | -- Damien Nadé Tue, 05 Sep 2017 13:57:55 +0200 6 | 7 | bash-argsparse (1.7) unstable; urgency=low 8 | 9 | * Version 1.7 10 | 11 | -- Damien Nadé Thu, 5 Mar 2015 12:20:00 +0100 12 | 13 | bash-argsparse (1.6.2) unstable; urgency=low 14 | 15 | * Version 1.6.2 16 | 17 | -- Damien Nadé Thu, 22 Jan 2015 16:35:00 +0100 18 | 19 | bash-argsparse (1.6.1) unstable; urgency=low 20 | 21 | * Version 1.6.1 22 | 23 | -- Damien Nadé Thu, 10 Oct 2014 19:40:00 +0200 24 | 25 | bash-argsparse (1.6) unstable; urgency=low 26 | 27 | * Version 1.6 28 | * Doxygen documentation 29 | 30 | -- Damien Nadé Mon, 13 Jan 2014 10:31:12 +0100 31 | 32 | bash-argsparse (1.5) unstable; urgency=low 33 | 34 | * Initial packaging 35 | 36 | -- Damien Nadé Mon, 18 Mar 2013 12:39:40 +0200 37 | 38 | -------------------------------------------------------------------------------- /tutorial/5-custom-types: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | PATH="..:$PATH" 4 | 5 | # Load argsparse library. 6 | . argsparse.sh 7 | 8 | # Argsparse also allows user-defined types. To do so, just define a 9 | # check_option_type_ function. 10 | # E.g, for a `binary' type. 11 | 12 | check_option_type_binary() { 13 | local value=$1 14 | # the function must return 0 if the provided argument (the value 15 | # submitted by the user) is valid. 16 | [[ "$value" =~ ^[01]+$ ]] 17 | } 18 | 19 | # This function allows you to give the 'type' property the value 20 | # 'binary'. 21 | argsparse_use_option bin-option "An binary word." type:binary value 22 | 23 | printf -v argsparse_usage_description "%s\n" \ 24 | "A example script using user-defined types." \ 25 | "Try command lines such as:" \ 26 | " $0 --bin-option something-wrong" \ 27 | " $0 --bin-option 0101010101111" 28 | 29 | # Command line parsing is done here. 30 | argsparse_parse_options "$@" 31 | 32 | printf "Options reporting:\n" 33 | # Simple reporting function. 34 | argsparse_report 35 | printf "End of argsparse report.\n\n" 36 | -------------------------------------------------------------------------------- /tutorial/0-completion: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | tutorial_directory=${BASH_SOURCE[0]%/*} 4 | 5 | # This script creates a custom (volatile) bashrc that will basically 6 | # just enable programmable completion for other tutorial scripts and 7 | # invoke an interactive shell 8 | read -N 4096 bashrc <\\\\n\\\\n" 23 | EOF 24 | exec bash --rcfile <(printf %s "$bashrc") -i 25 | 26 | cat <_values, which will contain the 15 | # acceptable values for said option. 16 | option_option1_values=(only accepting those values) 17 | # Acceptable values are mentioned in argsparse usage. 18 | 19 | # And, after either type checking of enumerated values checking, you 20 | # have the possibility to simply define a function named 21 | # check_value_of_. If the function return with value 0, it 22 | # means the value is correct. Any other value returned by the function 23 | # would make the value incorrect. 24 | argsparse_use_option option2 "An always bad option." value 25 | check_value_of_option2() { 26 | # So, this would make all values return an error. 27 | false 28 | } 29 | 30 | # If an option name contains '-' chars... 31 | argsparse_use_option long-option "An option with a long name." value 32 | # ... then the array name... 33 | option_long_option_values=(long option acceptable values) 34 | # ... and the function name must have '_' in place of '-'. 35 | check_value_of_long_option() { 36 | local value=$1 37 | [[ "$value" = long ]] 38 | } 39 | 40 | # 41 | printf -v argsparse_usage_description "%s\n" \ 42 | "A tutorial script teaching advanced value checking." \ 43 | "Try command lines such as:" \ 44 | " $0" \ 45 | " $0 -h" \ 46 | " $0 --option1 only" \ 47 | " $0 --option2 something" \ 48 | " $0 --long-option only" 49 | 50 | # Command line parsing is done here. 51 | argsparse_parse_options "$@" 52 | 53 | printf "Options reporting:\n" 54 | # Simple reporting function. 55 | argsparse_report 56 | printf "End of argsparse report.\n\n" 57 | -------------------------------------------------------------------------------- /tutorial/3-cumulative-options: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | PATH="..:$PATH" 4 | 5 | # Load argsparse library. 6 | . argsparse.sh 7 | 8 | # It is possible to have cumulative options with argsparse. Cumulative 9 | # options can be repeated and all values are kept in an array. 10 | # To have a cumulative option just declare an option with the 11 | # 'cumulative' property. 12 | argsparse_use_option =option1 "A cumulative option" cumulative 13 | # The user-given values will be stored in the array named 14 | # cumulated_values_