Skip to content

Commit

Permalink
Finalized 1.3.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Jul 23, 2016
1 parent e35c170 commit c590279
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 67 deletions.
6 changes: 4 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
1.2.2 (???)
1.3.0 (2016-07-23)
------------------

New features:

* Expanded documentation --- expanded info about related projects.
* Support for infinitely many (and leftover) arguments.
* Partial POSIX shell compatibility.

Bugfixes:

* Fixed definitions in the parsing part of the script.
* Expanded documentation --- expanded info about related projects.

1.2.1 (2016-07-10)
------------------
Expand Down
21 changes: 11 additions & 10 deletions bin/argbash.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION=1.2.1
VERSION=1.3.0
# DEFINE_SCRIPT_DIR()
# ARG_POSITIONAL_SINGLE([input],[The input template file])
# ARG_OPTIONAL_SINGLE([output],[o],[Name of the output file (pass '-' for stdout)],[-])
Expand All @@ -12,9 +12,10 @@ VERSION=1.2.1

# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY ARGBASH v1.2.1 one line above ###
### START OF CODE GENERATED BY ARGBASH v1.3.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, know your rights: https://github.com/matejak/argbash

# THE DEFAULTS INITIALIZATION --- POSITIONALS
# THE DEFAULTS INITIALIZATION --- OPTIONALS
_ARG_OUTPUT="-"
Expand All @@ -26,14 +27,14 @@ _ARG_DEBUG=
print_help ()
{
echo "Argbash is an argument parser generator for Bash."
echo "Usage: $0 [-o|--output <arg>] [--(no-)standalone] [-I|--search] [--debug <arg>] [-v|--version] [-h|--help] <input>"
echo -e "\t: The input template file"
echo -e "\t-o,--output: Name of the output file (pass '-' for stdout)default: '"-"'"
echo -e "\t--standalone,--no-standalone: Whether the parsing code is in a standalone file. (off by default)"
echo -e "\t-I,--search: Directories to search for the wrapped scripts (directory of the template will be added to the end of the list) (default array: (".") )"
echo -e "\t--debug: (developer option) Tell autom4te to trace a macrono default"
echo -e "\t-v,--version: Prints version"
echo -e "\t-h,--help: Prints help"
printf "Usage: $0 [-o|--output <arg>] [--(no-)standalone] [-I|--search] [--debug <arg>] [-v|--version] [-h|--help] <input>\n"
printf "\t: The input template file\n"
printf "\t-o,--output: Name of the output file (pass '-' for stdout) (default: '"-"')\n"
printf "\t--standalone,--no-standalone: Whether the parsing code is in a standalone file. (off by default)\n"
printf "\t-I,--search: Directories to search for the wrapped scripts (directory of the template will be added to the end of the list) (default array: (".") )\n"
printf "\t--debug: (developer option) Tell autom4te to trace a macro (no default)\n"
printf "\t-v,--version: Prints version\n"
printf "\t-h,--help: Prints help\n"
}

# THE PARSING ITSELF
Expand Down
2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Limitations
#. The square brackets in your script should match (i.e. every opening square bracket ``[`` should be followed at some point by a closing square bracket ``]``).
More precisely, the number of closing square brackets ``]`` must not exceed the number of opening ``[``.
This limitation does apply to files that are processed by ``argbash.sh`` --- you are fine if you have the argument parsing code in a separate file and you don't use the ``INCLUDE_PARSING_CODE``.
#. The generated code generally contains bashisms as it --- relies heavily on ``bash`` arrays to process any kind of positional arguments and multi-valued optional arguments.
That said, if you stick with optional arguments only, a POSIX shell s.a. ``dash`` will be able to process the ``Argbash``-generated parsing code.

Index
-----
Expand Down
21 changes: 11 additions & 10 deletions resources/examples/minimal.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#!/bin/bash

# _ARG_POSITIONAL_SINGLE([positional-arg],[Positional arg description])
# ARG_POSITIONAL_SINGLE([positional-arg],[Positional arg description])
# ARG_OPTIONAL_SINGLE([option],[o],[A option with short and long flags and default],[b])
# ARG_OPTIONAL_BOOLEAN([print],[],[A boolean option with long flag (and implicit default: off)],[])
# ARG_VERSION([echo $0 v0.1])
# ARG_HELP([This is a minimal demo of Argbash potential])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY ARGBASH v1.2.1 one line above ###
### START OF CODE GENERATED BY ARGBASH v1.3.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, know your rights: https://github.com/matejak/argbash

# THE DEFAULTS INITIALIZATION --- POSITIONALS
# THE DEFAULTS INITIALIZATION --- OPTIONALS
_ARG_OPTION="b"
_ARG_PRINT=off

# THE PRINT HELP FUNCION
function print_help
print_help ()
{
echo "This is a minimal demo of Argbash potential"
echo "Usage: $0 [--option <arg>] [--(no-)print] [--version] [--help] <positional-arg>"
echo -e "\t<positional-arg>: Positional arg description"
echo -e "\t-o,--option: A option with short and long flags and default (default: '"b"')"
echo -e "\t--print,--no-print: A boolean option with long flag (and implicit default: off) (default: 'off')"
echo -e "\t-v,--version: Prints version"
echo -e "\t-h,--help: Prints help"
printf "Usage: $0 [-o|--option <arg>] [--(no-)print] [-v|--version] [-h|--help] <positional-arg>\n"
printf "\t: Positional arg description\n"
printf "\t-o,--option: A option with short and long flags and default (default: '"b"')\n"
printf "\t--print,--no-print: A boolean option with long flag (and implicit default: off) (off by default)\n"
printf "\t-v,--version: Prints version\n"
printf "\t-h,--help: Prints help\n"
}

# THE PARSING ITSELF
Expand Down Expand Up @@ -61,7 +62,7 @@ done
POSITIONAL_NAMES=('_ARG_POSITIONAL_ARG' )
test ${#POSITIONALS[@]} -lt 1 && { ( echo "FATAL ERROR: Not enough positional arguments --- we require exactly 1, but got only ${#POSITIONALS[@]}."; print_help ) >&2; exit 1; }
test ${#POSITIONALS[@]} -gt 1 && { ( echo "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1, but got ${#POSITIONALS[@]} (the last one was: '${POSITIONALS[@]: -1}')."; print_help ) >&2; exit 1; }
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
do
eval "${POSITIONAL_NAMES[$ii]}=\"${POSITIONALS[$ii]}\"" || { echo "Error during argument parsing, possibly an Argbash bug." >&2; exit 1; }
done
Expand Down
19 changes: 9 additions & 10 deletions resources/examples/simple-standalone.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
#!/bin/bash

# _ARG_POSITIONAL_SINGLE([filename])
# ARG_POSITIONAL_SINGLE([filename])
# ARG_OPTIONAL_SINGLE([unit],[u],[What unit we accept (b for bytes, k for kilobytes, M for megabytes)],[b])
# ARG_VERSION([echo $0 v0.1])
# ARG_OPTIONAL_BOOLEAN([verbose])
# ARG_HELP()
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY ARGBASH v1.2.1 one line above ###
### START OF CODE GENERATED BY ARGBASH v1.3.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, know your rights: https://github.com/matejak/argbash

# THE DEFAULTS INITIALIZATION --- POSITIONALS
# THE DEFAULTS INITIALIZATION --- OPTIONALS
_ARG_UNIT="b"
_ARG_VERBOSE=off

# THE PRINT HELP FUNCION
function print_help
print_help ()
{
echo "Usage: $0 [--unit <arg>] [--version] [--(no-)verbose] [--help] <filename>"
echo -e "\t<filename>: "
echo -e "\t-u,--unit: What unit we accept (b for bytes, k for kilobytes, M for megabytes) (default: '"b"')"
echo -e "\t-v,--version: Prints version"
echo -e "\t--verbose,--no-verbose: (default: 'off')"
echo -e "\t-h,--help: Prints help"
printf "Usage: $0 [-u|--unit <arg>] [-v|--version] [--(no-)verbose] [-h|--help] <filename>\n"
printf "\t-u,--unit: What unit we accept (b for bytes, k for kilobytes, M for megabytes) (default: '"b"')\n"
printf "\t-v,--version: Prints version\n"
printf "\t-h,--help: Prints help\n"
}

# THE PARSING ITSELF
Expand Down Expand Up @@ -60,7 +59,7 @@ done
POSITIONAL_NAMES=('_ARG_FILENAME' )
test ${#POSITIONALS[@]} -lt 1 && { ( echo "FATAL ERROR: Not enough positional arguments --- we require exactly 1, but got only ${#POSITIONALS[@]}."; print_help ) >&2; exit 1; }
test ${#POSITIONALS[@]} -gt 1 && { ( echo "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1, but got ${#POSITIONALS[@]} (the last one was: '${POSITIONALS[@]: -1}')."; print_help ) >&2; exit 1; }
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
do
eval "${POSITIONAL_NAMES[$ii]}=\"${POSITIONALS[$ii]}\"" || { echo "Error during argument parsing, possibly an Argbash bug." >&2; exit 1; }
done
Expand Down
17 changes: 8 additions & 9 deletions resources/examples/simple-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#!/bin/bash

# _ARG_POSITIONAL_SINGLE([directory])
# ARG_POSITIONAL_SINGLE([directory])
# ARGBASH_WRAP([simple],[filename])
# ARG_HELP([This program tells you size of files in a given directory in units you choose.])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY ARGBASH v1.2.1 one line above ###
### START OF CODE GENERATED BY ARGBASH v1.3.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, know your rights: https://github.com/matejak/argbash

# THE DEFAULTS INITIALIZATION --- POSITIONALS
# THE DEFAULTS INITIALIZATION --- OPTIONALS
_ARG_UNIT="b"
_ARG_VERBOSE=off

# THE PRINT HELP FUNCION
function print_help
print_help ()
{
echo "This program tells you size of files in a given directory in units you choose."
echo "Usage: $0 [--unit <arg>] [--(no-)verbose] [--help] <directory>"
echo -e "\t<directory>: "
echo -e "\t-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: '"b"')"
echo -e "\t--verbose,--no-verbose: (default: 'off')"
echo -e "\t-h,--help: Prints help"
printf "Usage: $0 [-u|--unit <arg>] [--(no-)verbose] [-h|--help] <directory>\n"
printf "\t-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: '"b"')\n"
printf "\t-h,--help: Prints help\n"
}

# THE PARSING ITSELF
Expand Down Expand Up @@ -54,7 +53,7 @@ done
POSITIONAL_NAMES=('_ARG_DIRECTORY' )
test ${#POSITIONALS[@]} -lt 1 && { ( echo "FATAL ERROR: Not enough positional arguments --- we require exactly 1, but got only ${#POSITIONALS[@]}."; print_help ) >&2; exit 1; }
test ${#POSITIONALS[@]} -gt 1 && { ( echo "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1, but got ${#POSITIONALS[@]} (the last one was: '${POSITIONALS[@]: -1}')."; print_help ) >&2; exit 1; }
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
do
eval "${POSITIONAL_NAMES[$ii]}=\"${POSITIONALS[$ii]}\"" || { echo "Error during argument parsing, possibly an Argbash bug." >&2; exit 1; }
done
Expand Down
19 changes: 9 additions & 10 deletions resources/examples/simple.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
#!/bin/bash

# _ARG_POSITIONAL_SINGLE([filename])
# ARG_POSITIONAL_SINGLE([filename])
# ARG_OPTIONAL_SINGLE([unit],[u],[What unit we accept (b for bytes, k for kibibytes, M for mebibytes)],[b])
# ARG_VERSION([echo $0 v0.1])
# ARG_OPTIONAL_BOOLEAN([verbose])
# ARG_HELP([This program tells you size of file that you pass to it in chosen units.])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY ARGBASH v1.2.1 one line above ###
### START OF CODE GENERATED BY ARGBASH v1.3.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, know your rights: https://github.com/matejak/argbash

# THE DEFAULTS INITIALIZATION --- POSITIONALS
# THE DEFAULTS INITIALIZATION --- OPTIONALS
_ARG_UNIT="b"
_ARG_VERBOSE=off

# THE PRINT HELP FUNCION
function print_help
print_help ()
{
echo "This program tells you size of file that you pass to it in chosen units."
echo "Usage: $0 [--unit <arg>] [--version] [--(no-)verbose] [--help] <filename>"
echo -e "\t<filename>: "
echo -e "\t-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: '"b"')"
echo -e "\t-v,--version: Prints version"
echo -e "\t--verbose,--no-verbose: (default: 'off')"
echo -e "\t-h,--help: Prints help"
printf "Usage: $0 [-u|--unit <arg>] [-v|--version] [--(no-)verbose] [-h|--help] <filename>\n"
printf "\t-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: '"b"')\n"
printf "\t-v,--version: Prints version\n"
printf "\t-h,--help: Prints help\n"
}

# THE PARSING ITSELF
Expand Down Expand Up @@ -61,7 +60,7 @@ done
POSITIONAL_NAMES=('_ARG_FILENAME' )
test ${#POSITIONALS[@]} -lt 1 && { ( echo "FATAL ERROR: Not enough positional arguments --- we require exactly 1, but got only ${#POSITIONALS[@]}."; print_help ) >&2; exit 1; }
test ${#POSITIONALS[@]} -gt 1 && { ( echo "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1, but got ${#POSITIONALS[@]} (the last one was: '${POSITIONALS[@]: -1}')."; print_help ) >&2; exit 1; }
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
do
eval "${POSITIONAL_NAMES[$ii]}=\"${POSITIONALS[$ii]}\"" || { echo "Error during argument parsing, possibly an Argbash bug." >&2; exit 1; }
done
Expand Down
31 changes: 16 additions & 15 deletions src/stuff.m4
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,11 @@ m4_define([ARG_OPTIONAL_SINGLE], [m4_do(


m4_define([ARG_POSITIONAL_DOUBLEDASH], [m4_do(
[m4_ifblank(m4_list_contains([BLACKLIST], [--]), [_ARG_POSITIONAL_DOUBLEDASH($@)])],
[m4_ifblank(m4_list_contains([BLACKLIST], [--]), [[$0($@)]_ARG_POSITIONAL_DOUBLEDASH($@)])],
)])


m4_define([_ARG_POSITIONAL_DOUBLEDASH], [m4_do(
[[$0($@)]],
[m4_define([HAVE_DOUBLEDASH], 1)],
)])

Expand Down Expand Up @@ -399,7 +398,7 @@ dnl $1 = short name (opt)
m4_define([ARG_VERBOSE], [m4_do(
[[$0($@)]],
[_A_OPTIONAL],
[_ARG_OPTIONAL_INCREMENTAL([verbose], [$1], [Set verbose output (can be specified multiple times to increase the effect)])],
[_ARG_OPTIONAL_INCREMENTAL([verbose], [$1], [Set verbose output (can be specified multiple times to increase the effect)], 0)],
)])
Expand All @@ -411,7 +410,7 @@ m4_define([ARG_OPTIONAL_BOOLEAN], [m4_do(
[[$0($@)]],
[_A_OPTIONAL],
[_some_opt([$1], [$2], [$3],
m4_ifnblank([$4], [$4], [off]), [bool])],
m4_default([$4], [off]), [bool])],
)])
Expand Down Expand Up @@ -474,9 +473,9 @@ m4_define([_POS_ARG_HELP_USAGE], [m4_do(
[single],
[m4_if(_min_argn, 0, [m4_do(
[ @{:@],
[default: '"],
[default: '\n"],
[_defaults],
["'],
[\n"'],
[@:}@],
)])],
[more], [_MAKE_USAGE_MORE],
Expand Down Expand Up @@ -506,7 +505,7 @@ m4_define([_MAKE_HELP], [m4_do(
],
m4_ifnblank(m4_expand([_HELP_MSG]), m4_expand([[ echo] "_HELP_MSG"
])),
[ echo "Usage: $[]0],
[ printf "Usage: $[]0],
[dnl If we have optionals, display them like [--opt1 arg] [--(no-)opt2] ... according to their type. @<:@ becomes square bracket at the end of processing
],
[m4_if(HAVE_OPTIONAL, 1,
Expand Down Expand Up @@ -534,7 +533,7 @@ m4_define([_MAKE_HELP], [m4_do(
)])],
[ m4_join([ ], m4_unquote(m4_list_contents([_POSITIONALS_LIST])))],
)])],
["
[\n"
],
[dnl Don't display extended help for an arg if it doesn't have a description
],
Expand All @@ -546,7 +545,7 @@ m4_define([_MAKE_HELP], [m4_do(
[m4_pushdef([argname], m4_if(m4_list_nth(_POSITIONALS_TYPES, idx), [inf], [m4_default(_INF_REPR, argname)]))],
[m4_pushdef([_min_argn], m4_expand([m4_list_nth([_POSITIONALS_MINS], idx)]))],
[m4_pushdef([_defaults], m4_expand([m4_list_nth([_POSITIONALS_DEFAULTS], idx)]))],
[[ echo -e "\t]argname[: ]],
[[ printf "\t]argname[: ]],
[m4_list_nth([_POSITIONALS_MSGS], idx)],
[dnl Check whether we have defaults
],
Expand All @@ -555,7 +554,7 @@ m4_define([_MAKE_HELP], [m4_do(
[m4_popdef([_min_argn])],
[m4_popdef([argname])],
[m4_popdef([argname])],
[["
[[\n"
]],
)])])],
)],
Expand All @@ -564,7 +563,7 @@ m4_define([_MAKE_HELP], [m4_do(
[dnl Plus, don't display extended help for an arg if it doesn't have a description
],
[m4_if(_NARGS, 0, [], [m4_for([idx], 1, _NARGS, 1, [m4_ifnblank(m4_list_nth([_ARGS_HELP], idx), [m4_do(
[ echo -e "\t],
[ printf "\t],
[dnl Display a short one if it is not blank
],
[m4_ifnblank(m4_list_nth([_ARGS_SHORT], idx), -m4_list_nth([_ARGS_SHORT], idx)[,])],
Expand All @@ -586,7 +585,7 @@ m4_define([_MAKE_HELP], [m4_do(
[bool], [ (m4_list_nth([_ARGS_DEFAULT], idx) by default)],
[repeated], [ (default array: m4_list_nth([_ARGS_DEFAULT], idx) )],
[ @{:@m4_ifnblank(m4_list_nth([_ARGS_DEFAULT], idx), [default: 'm4_list_nth([_ARGS_DEFAULT], idx)'], [no default])@:}@])],
["
[\n"
],
)])])])],
[}
Expand Down Expand Up @@ -746,12 +745,13 @@ test ${#POSITIONALS[@]} -lt ]],
[m4_do(
[dnl If we allow up to infinitely many args, we prepare the array for it.
],
[OUR_ARGS=$((${#POSITIONALS@<:@@@:>@} - ${#POSITIONAL_NAMES@<:@@@:>@}))
[_OUR_ARGS=$((${#POSITIONALS@<:@@@:>@} - ${#POSITIONAL_NAMES@<:@@@:>@}))
],
[for (( ii = 0; ii < $OUR_ARGS; ii++))
[for (( ii = 0; ii < $_OUR_ARGS; ii++))
do
POSITIONAL_NAMES+=("_INF_VARNAME@<:@(($ii + _INF_ARGN))@:>@")
done
],
)],
[m4_do(
Expand All @@ -766,11 +766,11 @@ done
[[, but got ${#POSITIONALS[@]} (the last one was: '${POSITIONALS[@]: -1}')."; print_help ) >&2; exit 1; }
]],
)])],
[m4_popdef([_NARGS_SPEC])],
[[for (( ii = 0; ii < ${#POSITIONALS[@]}; ii++))
do
eval "${POSITIONAL_NAMES[$ii]}=\"${POSITIONALS[$ii]}\"" || { echo "Error during argument parsing, possibly an Argbash bug." >&2; exit 1; }
done]],
[m4_popdef([_NARGS_SPEC])],
[
],
[m4_list_ifempty([_WRAPPED_ADD_SINGLE], [], [m4_set_foreach([_POS_VARNAMES], [varname], [varname=@{:@@:}@
Expand Down Expand Up @@ -874,6 +874,7 @@ m4_define([ARGBASH_GO_BASE], [m4_do(
### START OF CODE GENERATED BY ARGBASH v]_ARGBASH_VERSION[ one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, know your rights: https://github.com/matejak/argbash
]],
[m4_if(_NO_ARGS_WHATSOEVER, 1, [], [m4_do(
[_MAKE_DEFAULTS
Expand Down
2 changes: 1 addition & 1 deletion src/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.3.0

0 comments on commit c590279

Please sign in to comment.