Skip to content

Commit 3b4fcc1

Browse files
committed
New version setup, fixed minor issues.
1 parent 55d2015 commit 3b4fcc1

20 files changed

+93
-65
lines changed

ChangeLog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
2.7.0 (TBA)
1+
2.7.0 (2018-07-18)
22
------------------
33

44
New features:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Following argument types are supported:
5555
Following outputs are available:
5656

5757
- Bash scripts, tailor-made bash parsing libraries.
58+
- POSIX scripts that use `getopts`, also tailor-made.
5859
- Bash completion.
5960
- [docopt](https://docopt.org)-compliant usage message.
6061

bin/argbash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SC2016: Expressions don't expand in single quotes, use double quotes for that.
55
# SC2059 Don't use variables in the printf format string.
66

7-
version=2.6.1
7+
version=2.7.0
88

99

1010
# DEFINE_SCRIPT_DIR()
@@ -25,7 +25,7 @@ version=2.6.1
2525

2626
# ARGBASH_GO()
2727
# needed because of Argbash --> m4_ignore([
28-
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
28+
### START OF CODE GENERATED BY Argbash v2.7.0 one line above ###
2929
# Argbash is a bash code generator used to get arguments parsing right.
3030
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
3131

bin/argbash-1to2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# shellcheck disable=SC2016
44
# SC2016: Expressions don't expand in single quotes, use double quotes for that.
55

6-
version=2.6.1
6+
version=2.7.0
77
# ARG_POSITIONAL_INF([input],[The input file to transform],[1])
88
# ARG_OPTIONAL_SINGLE([output],[o],[Name of the output file (pass '-' for stdout and empty string for the same as input file)],[""])
99
# ARG_VERSION([echo "argbash-1to2 v$version"])
1010
# ARG_HELP([Convert a template for argbash>=1,<2 to argbash>=2,<3])
1111

1212
# ARGBASH_GO()
1313
# needed because of Argbash --> m4_ignore([
14-
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
14+
### START OF CODE GENERATED BY Argbash v2.7.0 one line above ###
1515
# Argbash is a bash code generator used to get arguments parsing right.
1616
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
1717

bin/argbash-init

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SC2001: See if you can use ${variable//search/replace} instead.
55
# SC2016: Expressions don't expand in single quotes, use double quotes for that.
66

7-
version=2.6.1
7+
version=2.7.0
88
# ARG_POSITIONAL_SINGLE([output],[Name of the output template],[-])
99
# ARG_OPTIONAL_INCREMENTAL([separate],[s],[Separate the parsing logic (specify two times for complete separation)])
1010
# ARG_OPTIONAL_BOOLEAN([hints],[],[Whether to write hints to the script template])
@@ -19,7 +19,7 @@ version=2.6.1
1919

2020
# ARGBASH_GO()
2121
# needed because of Argbash --> m4_ignore([
22-
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
22+
### START OF CODE GENERATED BY Argbash v2.7.0 one line above ###
2323
# Argbash is a bash code generator used to get arguments parsing right.
2424
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
2525

doc/Makefile.pieces

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ $(STATICDIR)/minimal_init-create.txt: $(AB_INIT)
5151
$(CMD_OUT)
5252
$(RM) minimal.m4
5353

54-
$(STATICDIR)/index_script-create.txt: $(AB_INIT)
54+
$(STATICDIR)/index_script-create.txt: $(AB_INIT) $(INDEX_SCRIPT)
5555
$(eval FLAGS := $(A_INIT_ARGS) - | $(AB) -o $(INDEX_SCRIPT) -)
5656
$(CMD_OUT)
57-
$(RM) $(INDEX_SCRIPT)
5857

5958
$(STATICDIR)/index_script-help.txt: $(INDEX_SCRIPT)
6059
$(eval FLAGS := -h)
@@ -114,4 +113,4 @@ clean-pieces: clean-tmp
114113
$(RM) $(PIECES)
115114

116115
clean-tmp:
117-
$(RM) $(MINIMAL_SCRIPT) $(INDEX_SCRIPT)
116+
$(RM) $(MINIMAL_SCRIPT) $(INDEX_SCRIPT) $(MINIMAL_INIT_POST)

doc/_static/minimal.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@@ -3,16 +3,22 @@
44
# m4_ignore(
55
echo "This is just a script template, not the script (yet) - pass it to 'argbash' to fix this." >&2
6-
exit 11 #)Created by argbash-init v2.6.1
6+
exit 11 #)Created by argbash-init v@VERSION@
77
-# ARG_OPTIONAL_SINGLE([option])
88
-# ARG_OPTIONAL_BOOLEAN([print])
99
-# ARG_POSITIONAL_SINGLE([positional-arg])

doc/_static/simple-output-help.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ resources/examples/simple.sh -h
22

33
This program tells you size of file that you pass to it in chosen units.
44
Usage: ../resources/examples/simple.sh [-u|--unit <arg>] [-v|--version] [--(no-)verbose] [-h|--help] <filename>
5-
-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
6-
-v,--version: Prints version
7-
-h,--help: Prints help
5+
-u, --unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
6+
-v, --version: Prints version
7+
-h, --help: Prints help

doc/_static/wrapper-output-action.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Contents of '../src' matching '*.m4':
1515
output-bash-script.m4: 1 kiB
1616
output-completion.m4: 2 kiB
1717
output-docopt.m4: 2 kiB
18-
output-posix-script.m4: 2 kiB
18+
output-posix-script.m4: 3 kiB
1919
output-strip-all.m4: 0 kiB
2020
output-strip-none.m4: 0 kiB
2121
output-strip-user-content.m4: 0 kiB

doc/_static/wrapper-output-help.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ This program tells you size of specified files in given directories in units you
44
Usage: ../resources/examples/simple-wrapper.sh [--glob <arg>] [-u|--unit <arg>] [--(no-)verbose] [-h|--help] <directory-1> [<directory-2>] ... [<directory-n>] ...
55
<directory>: Directories to go through
66
--glob: What files to match in the directory (default: '*')
7-
-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
8-
-h,--help: Prints help
7+
-u, --unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
8+
-h, --help: Prints help

doc/conf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
# All configuration values have a default; values that are commented out
1414
# serve to show the default.
1515

16-
import sys
1716
import os
18-
import shlex
17+
import datetime
1918

2019

2120
version_fname = os.path.join('..', 'src', 'version')
@@ -55,9 +54,14 @@
5554

5655
# General information about the project.
5756
project = 'Argbash'
58-
copyright = u'2015--2017, Matěj Týč'
57+
copyright = u'2015–{0}, Matěj Týč'.format(datetime.datetime.now().year)
5958
author = u'Matěj Týč'
6059

60+
rst_epilog = """
61+
.. |current-year| date:: %Y
62+
"""
63+
64+
6165
# The version info for the project you're documenting, acts as replacement for
6266
# |version| and |release|, also used in various other places throughout the
6367
# built documents.

doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A basic template generator ``argbash-init`` is part of the package, and you can
2222
:Authors:
2323
`Matěj Týč <https://github.com/matejak>`_
2424
:Copyright:
25-
2014--2017, Matěj Týč
25+
2014--|current-year|, Matěj Týč
2626
:Website:
2727
https://argbash.io
2828

doc/others.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ Then read through this list of influences and/or alternatives!
6060

6161
* Supports only short optional arguments.
6262

63+
* Argbash says:
64+
65+
* ``argbash>=2.7.0`` can generate code that uses ``getopts`` in the :ref:`POSIX mode <posix>`, so there is no reason any longer to write that code manually.
66+
6367
.. _easy_options:
6468

6569
* ``EasyOptions``: ``Ruby`` utility with a ``bash`` interface as well as its pure ``bash`` implementation: https://github.com/renatosilva/easyoptions

doc/usage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ docopt help message docopt all
249249
============================ ======================= ==========================
250250

251251

252+
.. _posix:
253+
252254
POSIX script
253255
++++++++++++
254256

resources/examples/minimal-raw.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# m4_ignore(
44
echo "This is just a script template, not the script (yet) - pass it to 'argbash' to fix this." >&2
5-
exit 11 #)Created by argbash-init v2.6.1
5+
exit 11 #)Created by argbash-init v2.7.0
66
# ARG_OPTIONAL_SINGLE([option])
77
# ARG_OPTIONAL_BOOLEAN([print])
88
# ARG_POSITIONAL_SINGLE([positional-arg])

resources/examples/minimal.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# m4_ignore(
44
echo "This is just a script template, not the script (yet) - pass it to 'argbash' to fix this." >&2
5-
exit 11 #)Created by argbash-init v2.6.1
5+
exit 11 #)Created by argbash-init v2.7.0
66
# ARG_OPTIONAL_SINGLE([option], o, [A option with short and long flags and default], [boo])
77
# ARG_OPTIONAL_BOOLEAN([print], , [A boolean option with long flag (and implicit default: off)])
88
# ARG_POSITIONAL_SINGLE([positional-arg], [Positional arg description], )

resources/examples/simple-parsing.sh

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
# ARGBASH_SET_INDENT([ ])
99
# ARGBASH_GO()
1010
# needed because of Argbash --> m4_ignore([
11-
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
11+
### START OF CODE GENERATED BY Argbash v2.7.0 one line above ###
1212
# Argbash is a bash code generator used to get arguments parsing right.
1313
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
1414

15+
1516
die()
1617
{
1718
local _ret=$2
@@ -21,33 +22,34 @@ die()
2122
exit ${_ret}
2223
}
2324

25+
2426
begins_with_short_option()
2527
{
26-
local first_option all_short_options
27-
all_short_options='uvh'
28+
local first_option all_short_options='uvh'
2829
first_option="${1:0:1}"
2930
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
3031
}
3132

32-
33-
3433
# THE DEFAULTS INITIALIZATION - POSITIONALS
3534
_positionals=()
3635
# THE DEFAULTS INITIALIZATION - OPTIONALS
3736
_arg_unit="b"
3837
_arg_verbose="off"
3938

40-
print_help ()
39+
40+
print_help()
4141
{
4242
printf '%s\n' "This program tells you size of file that you pass to it in chosen units."
4343
printf 'Usage: %s [-u|--unit <arg>] [-v|--version] [--(no-)verbose] [-h|--help] <filename>\n' "$0"
44-
printf '\t%s\n' "-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')"
45-
printf '\t%s\n' "-v,--version: Prints version"
46-
printf '\t%s\n' "-h,--help: Prints help"
44+
printf '\t%s\n' "-u, --unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')"
45+
printf '\t%s\n' "-v, --version: Prints version"
46+
printf '\t%s\n' "-h, --help: Prints help"
4747
}
4848

49-
parse_commandline ()
49+
50+
parse_commandline()
5051
{
52+
_positionals_count=0
5153
while test $# -gt 0
5254
do
5355
_key="$1"
@@ -84,34 +86,41 @@ parse_commandline ()
8486
exit 0
8587
;;
8688
*)
87-
_positionals+=("$1")
89+
_last_positional="$1"
90+
_positionals+=("$_last_positional")
91+
_positionals_count=$((_positionals_count + 1))
8892
;;
8993
esac
9094
shift
9195
done
9296
}
9397

9498

95-
handle_passed_args_count ()
99+
handle_passed_args_count()
96100
{
97-
_required_args_string="'filename'"
98-
test ${#_positionals[@]} -ge 1 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${#_positionals[@]}." 1
99-
test ${#_positionals[@]} -le 1 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${#_positionals[@]} (the last one was: '${_positionals[*]: -1}')." 1
101+
local _required_args_string="'filename'"
102+
test "${_positionals_count}" -ge 1 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${_positionals_count}." 1
103+
test "${_positionals_count}" -le 1 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}')." 1
100104
}
101105

102-
assign_positional_args ()
106+
107+
assign_positional_args()
103108
{
104-
_positional_names=('_arg_filename' )
109+
local _positional_name _shift_for=$1
110+
_positional_names="_arg_filename "
105111

106-
for (( ii = 0; ii < ${#_positionals[@]}; ii++))
112+
shift "$_shift_for"
113+
for _positional_name in ${_positional_names}
107114
do
108-
eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1
115+
test $# -gt 0 || break
116+
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
117+
shift
109118
done
110119
}
111120

112121
parse_commandline "$@"
113122
handle_passed_args_count
114-
assign_positional_args
123+
assign_positional_args 1 "${_positionals[@]}"
115124

116125
# OTHER STUFF GENERATED BY Argbash
117126

0 commit comments

Comments
 (0)