Commit Graph

92 Commits

Author SHA1 Message Date
Kevin van Zonneveld
f77b400dc9 Fix main-repeated tests, flags weren't incremented before 2019-10-29 10:43:47 +01:00
Kevin van Zonneveld
b8a4aba3c2 Allow outputting both flags and arrays for arg_i and arg_x
This should later probably be split so we have dedicated varnames for the different types, as we're now making the template uglier just to accomodate our tests
2019-10-29 09:57:59 +01:00
Kevin van Zonneveld
4085bc461e -v operator was added in bash 4.2 while we target bash 3 2019-10-29 08:34:52 +01:00
gmeral
ea57d157c7 #111 more contrasted colors for alert and emergency (#112)
* Set alert and emergency colors to more readable values

* Add entry to CHANGELOG.md about #111
2019-09-20 11:43:30 +02:00
Lukas Stockner
95b9cb1469 Add support for repeatable arguments (#118)
* Add support for declaring arguments as repeatable

If the usage of the argument includes the phrase "Can be repeated.",
the corresponding arg_ variable will be an array containing one element
per instance of the argument.

* Add example and test for using repeated parameters

* Add example and test for using repeated flags
2019-09-20 11:40:06 +02:00
Lukas Stockner
664e55ad1e Fix or silence remaining warnings with shellcheck v0.7.0 (#117)
SC2235: The warning/suggestion about the subshell was letigimate, so
the suggested fix is implemented.

SC2034: The variable __invocation is indeed unused, but it's supposed
to be there in case the script using bash3boilerplate wants to use it,
so this commit silences the warning.

SC1102: The warning about the parsing of $((( is legitimate, so the
suggested fix is implemented.

SC2015: While the warning is correct in general, here 'true' has no
side effects hence it can be silenced.

Fixes #107.
2019-09-20 11:30:59 +02:00
QwertyZW
7b7d31a1bf Improve debug mode (#103)
Add file, line number, function name and function line offset
2019-05-06 10:04:09 +02:00
Manuel Streuhofer
ba0e7150cb close issue #108 (#109)
* added test for issue-108

* Closes #108

* fixed some easy shellcheck complaints

* trying to fix travis/debian-sid/shellcheck problem
2018-09-03 12:00:55 +02:00
Gabriel A. Devenyi
2048e4303e Add || true to fix __invocation with no arguments (#102) 2018-06-26 15:55:16 +02:00
Gabriel A. Devenyi
327cba75c9 Add magic variable that stores the full command line invocation (#99)
Provides variable __invocation which contains the command line
with proper separators maintained.

Adapted from https://stackoverflow.com/a/36625791
2018-06-06 15:28:55 +02:00
A. G. Madi
2463cd6cc9 Allow counting how many times an argument is used. (#96)
An example of use would be the passing in of multiple -v options in some utilities to increase verbosity.
2018-01-22 15:21:48 +01:00
Manuel Streuhofer
236e3c7eca fix shellcheck errors
shellcheck 0.4.7 seems to have come up with new checks and now complains
about yet more possible issues. fixed them all as good as i could.
2018-01-21 23:02:03 +01:00
Germain Masse
12ea4dd75f
Enable color in screen or tmux 2017-08-13 21:08:59 +02:00
Izaak Beekman
cb29b2f984
Restore @mstreuhofer's changes that I clobbered 2017-02-10 19:00:00 -05:00
Izaak Beekman
0d1f488365
Fix shellchk and show usage for new magic var
Update acceptance tests
2017-02-10 18:58:35 -05:00
Manuel Streuhofer
d879ae1fe0 fixup example.sh like 2.3.0 main.sh
__i_am_main_script logic fixed for example.sh
added double-sourced test
2017-02-10 20:40:38 +01:00
Kevin van Zonneveld
382217eebf Update version 2017-02-10 15:32:48 +01:00
Izaak Beekman
7cf9ea708d Issue 44 issue 21 issue 47 (#85)
* Fix shifting over `--`: don't throw errexit

 Fixes #21

* Add error trapping (including Ctrl-C) info to FAQ

 Closes #47

* Add backtracing to help localize errors

 - Fixes #44
 - Backtracing is turned on when the debugging `-d` flag is passed,
   otherwise backtracing function defined but signal trap not set.
 - Update main-help fixture due to moving trap

* Untabify main.sh

 Might be a controversial move, but I loath tabs...

* Add checks for tab chars and trailing whitespace

 - Update poor-man's style enforcement script to check for these
   violations
 - Better document style guidlines in README with small tweaks

* Add a magic variable to indicate if being source

 if `__i_am_main_script=1 #true` then `main.sh` called directly
 Fixes #45
2017-02-10 15:03:07 +01:00
Manuel Streuhofer
d383e8c098 prepared changelog for release 2.2.0 (#82)
moved entries in changelog from `unreleased` to 2.1.0 (even
though technically it's too late for that since that version was already
released).

added new section for 2.2.0 and added some points on what changed.

bumped version to 2.2.0 in main.sh, example.sh and package.json

Closes #74
2016-12-21 09:29:02 +01:00
Manuel Streuhofer
cf85af8c15 brace all variables, used [[ instead of [ (#76)
Closes #33
2016-12-14 09:54:25 +01:00
Manuel Streuhofer
9350e0574c added automatic usage validation for required args
If the description of an option contains the single word sentence
'Required.' it is understood as a required argument and automatic
validation will make sure that it is set or end the script by calling
help.

Alternatively, if the argument within the __usage string is {arg}
instead of [arg] it is understood as a required argument and automatic
validation will make sure that it is set or end the script by calling
help (even if 'Required.' is not in the description).

Closes #22
2016-12-09 00:54:52 +01:00
Manuel Streuhofer
1e69fd5e21 removed all usage of eval, proper usage of unset
replaced all `eval` with `printf -v` for security reasons.

the behaviour of unset without -v/-f is actually undefined so make the
intent clear.
2016-12-06 18:06:25 +01:00
Izaak Beekman
68323978d4 Merge pull request #70 from mstreuhofer/color
Fix auto-color-off code

 Thanks to @mstreuhofer for another great contribution 🎊 🙇
2016-12-05 12:37:28 -05:00
Manuel Streuhofer
b8bdaf371a get rid of awk, sed & egrep usage 2016-12-03 18:52:40 +01:00
Manuel Streuhofer
290c65d4b9 fix auto-color-off code
turn off colors if NO_COLOR is "true" or TERM is not "xterm*" or STDERR
is not connected to a terminal, but ignore TERM and STDERR if NO_COLOR
is set to "false" explicitly.

Fixes #69
2016-12-03 18:52:10 +01:00
Manuel Streuhofer
9b739b4cf0 Fix some code caught by shellcheck (#68) 2016-12-01 14:40:56 +01:00
Manuel Streuhofer
539443b3ca Allow for multiline opt description in __usage. Fixes #7 2016-11-11 20:13:01 +01:00
Manuel Streuhofer
dfd799b4e5 b3bp sourced mode (#61)
If main.sh is being sourced instead of being executed it respects the
variables __usage and __helptext being defined beforehand. Its behaviour
will depend on the sourcing script. If __usage is defined but empty no
argument parsing is done. If __helptext is defined but empty no helptext
will be shown.

Logging support still exists as it did before. The environment variables
LOG_LEVEL and NO_COLOR are supported just as they were before.
2016-11-09 10:03:00 +01:00
Manuel Streuhofer
d2195eee3c mention the used license in each script header (#60)
turns out that the README.md explains that "... licensed under MIT ...
the LICENSE does not have to be bundled as long as ..." but the scripts
themselfs don't mention any license.

fixed that by adding a one line mention of the used license and the two
lines explaining that the header comments have to stay intact.
2016-11-08 21:15:46 +01:00
Kevin van Zonneveld
9928ef16d7 Update version 2016-11-08 13:07:29 +01:00
Manuel Streuhofer
f82bbe59b0 better logging. support for multiple lines. (#57)
* better logging: support for multiple lines

* renamed logging function from _fmt to __b3bp_log

* adding example to show how multiline logging works

the main idea is to be able to log e.g. the output of a command and
b3bp taking care of splitting and prefixing every line.

* simplified code, removed hacky space-at-EOL
2016-11-08 13:03:26 +01:00
Manuel Streuhofer
4445c181bb cleanup environment variables (#58)
all internally used variable names (e.g. the ones used while parsing
__usage and running the getopts loop) start with '__b3bp_tmp'. This
makes it easy to unset them all after the work is done.

additional bugfix: run getopts only if any options were actually
specified in __usage
2016-11-08 13:02:37 +01:00
Kevin van Zonneveld
35b51072b3 No more os detection (#41) 2016-06-24 13:12:41 +02:00
Kevin van Zonneveld
03a2ec5adf Better OS detection (#39) 2016-06-23 16:20:45 +02:00
Kevin van Zonneveld
818d7c81c7 Return Windows as OS when under Git Bash (?) #32 2016-06-22 09:52:38 +02:00
Kevin van Zonneveld
64488e569a For delete-key-friendliness, bundle the commandline definition block along with its parser 2016-06-21 13:49:11 +02:00
Kevin van Zonneveld
e0aadaf50c Comment each set with a single line 2016-06-21 13:48:37 +02:00
Kevin van Zonneveld
008face7c8 Less verbose header comments 2016-06-21 13:48:08 +02:00
Kevin van Zonneveld
4926bbc942 For delete-key-friendliness, don't crash on undeclared help vars 2016-06-21 13:38:47 +02:00
Kevin van Zonneveld
649b5a0f44 Introduce errtrace, which is on by default (BREAKING) 2016-06-21 13:36:48 +02:00
Kevin van Zonneveld
5ee427eef5 Allow adding a help that is not parsed. See #24 2016-06-21 12:30:12 +02:00
Kevin van Zonneveld
ae230acc3b Add best practice of using __double_underscore_prefixed_vars 2016-06-21 10:21:00 +02:00
Kevin van Zonneveld
18525f72da Make the license less restrictive. See #14 (#28)
* Make the license less restrictive. See #14

So that people can use _just_ main.sh without bothering with also
distributing the license

* Add license update to changelog

* Add a comment about expansion, see #26

* Use an unmodified MIT License, with the more permissive clause inside the code

As modifying the MIT License will needlessly (but rightfully) cause
suspicion

* Credit @bravo-kernel for his feedback

* Fix another typo

* Reword copyright
2016-06-20 09:57:31 +02:00
Kevin van Zonneveld
12f1013611 Credit @gdevenyi for his testing and suggestions 2016-06-19 13:17:52 +02:00
Kevin van Zonneveld
d70312e916 Add a comment about expansion, see #26 2016-06-19 13:13:38 +02:00
Kevin van Zonneveld
fc7802d707 Respect --no-color by setting the NO_COLOR flag in main.sh. Fixes #25. thx @gdevenyi 2016-06-19 13:06:53 +02:00
Kevin van Zonneveld
8687e384eb Split out changelog into separate file, credit @rouson for the FAQ 2016-03-03 12:45:07 +01:00
Izaak Beekman
a86d8d82b1
Mangle long-option names to allow dashes
Fixes problem where long options with dashes, like `--no-color` were
 broken. This was due to the fact that bash variable names must match
 `[_a-zA-Z][_0-9a-zA-Z]*` and the usage parsing and option handling was
 trying to create variables with dashes in their names. Short of
 employing Bash4 associative arrays, "name mangling" seemed like the
 best solution to this problem.

Solution: map dashes to underscores when creating bash variables in the
script that correspond to long option flags. The downside of this is
that `--no_color` and `--no-color` will collide, but users expecting to
use options that are identical except one has an underscore and the
other has a dash deserve the ensuing confusion.
2016-02-19 23:25:09 -05:00
Kevin van Zonneveld
db690268ea Whitespace 2016-02-17 13:46:05 +01:00
Kevin van Zonneveld
366d8c7c9c Update version 2016-02-17 13:41:46 +01:00