Skip to content

Commit

Permalink
New version setup, fixed minor issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Jul 18, 2018
1 parent 55d2015 commit 3b4fcc1
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 65 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
@@ -1,4 +1,4 @@
2.7.0 (TBA)
2.7.0 (2018-07-18)
------------------

New features:
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -55,6 +55,7 @@ Following argument types are supported:
Following outputs are available:

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

Expand Down
4 changes: 2 additions & 2 deletions bin/argbash
Expand Up @@ -4,7 +4,7 @@
# SC2016: Expressions don't expand in single quotes, use double quotes for that.
# SC2059 Don't use variables in the printf format string.

version=2.6.1
version=2.7.0


# DEFINE_SCRIPT_DIR()
Expand All @@ -25,7 +25,7 @@ version=2.6.1

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

Expand Down
4 changes: 2 additions & 2 deletions bin/argbash-1to2
Expand Up @@ -3,15 +3,15 @@
# shellcheck disable=SC2016
# SC2016: Expressions don't expand in single quotes, use double quotes for that.

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

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

Expand Down
4 changes: 2 additions & 2 deletions bin/argbash-init
Expand Up @@ -4,7 +4,7 @@
# SC2001: See if you can use ${variable//search/replace} instead.
# SC2016: Expressions don't expand in single quotes, use double quotes for that.

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

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

Expand Down
5 changes: 2 additions & 3 deletions doc/Makefile.pieces
Expand Up @@ -51,10 +51,9 @@ $(STATICDIR)/minimal_init-create.txt: $(AB_INIT)
$(CMD_OUT)
$(RM) minimal.m4

$(STATICDIR)/index_script-create.txt: $(AB_INIT)
$(STATICDIR)/index_script-create.txt: $(AB_INIT) $(INDEX_SCRIPT)
$(eval FLAGS := $(A_INIT_ARGS) - | $(AB) -o $(INDEX_SCRIPT) -)
$(CMD_OUT)
$(RM) $(INDEX_SCRIPT)

$(STATICDIR)/index_script-help.txt: $(INDEX_SCRIPT)
$(eval FLAGS := -h)
Expand Down Expand Up @@ -114,4 +113,4 @@ clean-pieces: clean-tmp
$(RM) $(PIECES)

clean-tmp:
$(RM) $(MINIMAL_SCRIPT) $(INDEX_SCRIPT)
$(RM) $(MINIMAL_SCRIPT) $(INDEX_SCRIPT) $(MINIMAL_INIT_POST)
2 changes: 1 addition & 1 deletion doc/_static/minimal.patch
Expand Up @@ -3,7 +3,7 @@
@@ -3,16 +3,22 @@
# m4_ignore(
echo "This is just a script template, not the script (yet) - pass it to 'argbash' to fix this." >&2
exit 11 #)Created by argbash-init v2.6.1
exit 11 #)Created by argbash-init v@VERSION@
-# ARG_OPTIONAL_SINGLE([option])
-# ARG_OPTIONAL_BOOLEAN([print])
-# ARG_POSITIONAL_SINGLE([positional-arg])
Expand Down
6 changes: 3 additions & 3 deletions doc/_static/simple-output-help.txt
Expand Up @@ -2,6 +2,6 @@ resources/examples/simple.sh -h

This program tells you size of file that you pass to it in chosen units.
Usage: ../resources/examples/simple.sh [-u|--unit <arg>] [-v|--version] [--(no-)verbose] [-h|--help] <filename>
-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
-v,--version: Prints version
-h,--help: Prints help
-u, --unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
-v, --version: Prints version
-h, --help: Prints help
2 changes: 1 addition & 1 deletion doc/_static/wrapper-output-action.txt
Expand Up @@ -15,7 +15,7 @@ Contents of '../src' matching '*.m4':
output-bash-script.m4: 1 kiB
output-completion.m4: 2 kiB
output-docopt.m4: 2 kiB
output-posix-script.m4: 2 kiB
output-posix-script.m4: 3 kiB
output-strip-all.m4: 0 kiB
output-strip-none.m4: 0 kiB
output-strip-user-content.m4: 0 kiB
Expand Down
4 changes: 2 additions & 2 deletions doc/_static/wrapper-output-help.txt
Expand Up @@ -4,5 +4,5 @@ This program tells you size of specified files in given directories in units you
Usage: ../resources/examples/simple-wrapper.sh [--glob <arg>] [-u|--unit <arg>] [--(no-)verbose] [-h|--help] <directory-1> [<directory-2>] ... [<directory-n>] ...
<directory>: Directories to go through
--glob: What files to match in the directory (default: '*')
-u,--unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
-h,--help: Prints help
-u, --unit: What unit we accept (b for bytes, k for kibibytes, M for mebibytes) (default: 'b')
-h, --help: Prints help
10 changes: 7 additions & 3 deletions doc/conf.py
Expand Up @@ -13,9 +13,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import shlex
import datetime


version_fname = os.path.join('..', 'src', 'version')
Expand Down Expand Up @@ -55,9 +54,14 @@

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

rst_epilog = """
.. |current-year| date:: %Y
"""


# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Expand Up @@ -22,7 +22,7 @@ A basic template generator ``argbash-init`` is part of the package, and you can
:Authors:
`Matěj Týč <https://github.com/matejak>`_
:Copyright:
2014--2017, Matěj Týč
2014--|current-year|, Matěj Týč
:Website:
https://argbash.io

Expand Down
4 changes: 4 additions & 0 deletions doc/others.rst
Expand Up @@ -60,6 +60,10 @@ Then read through this list of influences and/or alternatives!

* Supports only short optional arguments.

* Argbash says:

* ``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.

.. _easy_options:

* ``EasyOptions``: ``Ruby`` utility with a ``bash`` interface as well as its pure ``bash`` implementation: https://github.com/renatosilva/easyoptions
Expand Down
2 changes: 2 additions & 0 deletions doc/usage.rst
Expand Up @@ -249,6 +249,8 @@ docopt help message docopt all
============================ ======================= ==========================


.. _posix:

POSIX script
++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion resources/examples/minimal-raw.m4
Expand Up @@ -2,7 +2,7 @@

# m4_ignore(
echo "This is just a script template, not the script (yet) - pass it to 'argbash' to fix this." >&2
exit 11 #)Created by argbash-init v2.6.1
exit 11 #)Created by argbash-init v2.7.0
# ARG_OPTIONAL_SINGLE([option])
# ARG_OPTIONAL_BOOLEAN([print])
# ARG_POSITIONAL_SINGLE([positional-arg])
Expand Down
2 changes: 1 addition & 1 deletion resources/examples/minimal.m4
Expand Up @@ -2,7 +2,7 @@

# m4_ignore(
echo "This is just a script template, not the script (yet) - pass it to 'argbash' to fix this." >&2
exit 11 #)Created by argbash-init v2.6.1
exit 11 #)Created by argbash-init v2.7.0
# ARG_OPTIONAL_SINGLE([option], o, [A option with short and long flags and default], [boo])
# ARG_OPTIONAL_BOOLEAN([print], , [A boolean option with long flag (and implicit default: off)])
# ARG_POSITIONAL_SINGLE([positional-arg], [Positional arg description], )
Expand Down
49 changes: 29 additions & 20 deletions resources/examples/simple-parsing.sh
Expand Up @@ -8,10 +8,11 @@
# ARGBASH_SET_INDENT([ ])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
### START OF CODE GENERATED BY Argbash v2.7.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info


die()
{
local _ret=$2
Expand All @@ -21,33 +22,34 @@ die()
exit ${_ret}
}


begins_with_short_option()
{
local first_option all_short_options
all_short_options='uvh'
local first_option all_short_options='uvh'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}



# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_unit="b"
_arg_verbose="off"

print_help ()

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

parse_commandline ()

parse_commandline()
{
_positionals_count=0
while test $# -gt 0
do
_key="$1"
Expand Down Expand Up @@ -84,34 +86,41 @@ parse_commandline ()
exit 0
;;
*)
_positionals+=("$1")
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
;;
esac
shift
done
}


handle_passed_args_count ()
handle_passed_args_count()
{
_required_args_string="'filename'"
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
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
local _required_args_string="'filename'"
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
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
}

assign_positional_args ()

assign_positional_args()
{
_positional_names=('_arg_filename' )
local _positional_name _shift_for=$1
_positional_names="_arg_filename "

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

parse_commandline "$@"
handle_passed_args_count
assign_positional_args
assign_positional_args 1 "${_positionals[@]}"

# OTHER STUFF GENERATED BY Argbash

Expand Down

0 comments on commit 3b4fcc1

Please sign in to comment.