Skip to content

Commit 6049534

Browse files
authored
Merge pull request #95 from matejak/no_readlink_e
Reverted the DEFINE_SCRIPT_DIR to compatible mode.
2 parents 59cfef6 + f0a2229 commit 6049534

File tree

7 files changed

+55
-10
lines changed

7 files changed

+55
-10
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
2.8.1 (TBA)
22
------------------
33

4+
Incompatible changes (minor):
5+
6+
* The `DEFINE_SCRIPT_DIR` macro doesn't resolve symlinks as it started to do so in `2.8.0`, use `DEFINE_SCRIPT_DIR_GNU` if you need the functionality.
7+
48
New features:
59

610
* The help message now contains reference for one-of argument types (#76).
@@ -9,6 +13,7 @@ Bugfixes:
913

1014
* The environment variables help message has been fixed (#79).
1115
* The manpage generation works when long description is supplied (#78).
16+
* The `DEFINE_SCRIPT_DIR` macro doesn't use `readlink -e` any more (#74).
1217

1318

1419
2.8.0 (2019-01-26)

bin/argbash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# SC2059 Don't use variables in the printf format string.
66

77

8-
# DEFINE_SCRIPT_DIR()
8+
# DEFINE_SCRIPT_DIR()_DEFINE_SCRIPT_DIR([],[cd "$(dirname "${BASH_SOURCE[0]}")" && pwd])
99
# ARG_POSITIONAL_SINGLE([input],[The input template file (pass '-' for stdin)])
1010
# ARG_OPTIONAL_SINGLE([output],[o],[Name of the output file (pass '-' for stdout)],[-])
1111
# ARG_OPTIONAL_SINGLE([type],[t],[Output type to generate],[bash-script])
@@ -232,7 +232,7 @@ handle_passed_args_count
232232
assign_positional_args 1 "${_positionals[@]}"
233233

234234
# OTHER STUFF GENERATED BY Argbash
235-
script_dir="$(cd "$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")" && pwd)" || die "Couldn't determine the script's running directory, which probably matters, bailing out" 2
235+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || die "Couldn't determine the script's running directory, which probably matters, bailing out" 2
236236
# Validation of values
237237

238238

@@ -460,7 +460,7 @@ then
460460
# match against suspicious, then inverse match against correct stuff:
461461
# #<optional whitespace>\(allowed\|another allowed\|...\)<optional whitespace><opening bracket <or> end of line>
462462
# Then, extract all matches (assumed to be alnum chars + '_') from grep and put them in the error msg.
463-
grep_output="$(printf "%s" "$output" | grep '^#\s*\(ARG_\|ARGBASH\)' | grep -v '^#\s*\(ARGBASH_SET_INDENT\|ARG_OPTIONAL_SINGLE\|ARG_VERSION\|ARG_VERSION_AUTO\|ARG_HELP\|ARG_OPTIONAL_INCREMENTAL\|ARG_OPTIONAL_REPEATED\|ARG_VERBOSE\|ARG_OPTIONAL_BOOLEAN\|ARG_OPTIONAL_ACTION\|ARG_POSITIONAL_SINGLE\|ARG_POSITIONAL_INF\|ARG_POSITIONAL_MULTI\|ARG_POSITIONAL_DOUBLEDASH\|ARG_OPTION_STACKING\|ARG_RESTRICT_VALUES\|ARG_DEFAULTS_POS\|ARG_LEFTOVERS\|ARGBASH_WRAP\|INCLUDE_PARSING_CODE\|DEFINE_SCRIPT_DIR\|ARGBASH_SET_DELIM\|ARGBASH_GO\|ARGBASH_PREPARE\|ARG_TYPE_GROUP\|ARG_TYPE_GROUP_SET\|ARG_USE_ENV\|ARG_USE_PROG\)\s*\((\|$\)' | sed -e 's/#\s*\([[:alnum:]_]*\).*/\1 /' | tr -d '\n\r')"
463+
grep_output="$(printf "%s" "$output" | grep '^#\s*\(ARG_\|ARGBASH\)' | grep -v '^#\s*\(ARGBASH_SET_INDENT\|ARG_OPTIONAL_SINGLE\|ARG_VERSION\|ARG_VERSION_AUTO\|ARG_HELP\|ARG_OPTIONAL_INCREMENTAL\|ARG_OPTIONAL_REPEATED\|ARG_VERBOSE\|ARG_OPTIONAL_BOOLEAN\|ARG_OPTIONAL_ACTION\|ARG_POSITIONAL_SINGLE\|ARG_POSITIONAL_INF\|ARG_POSITIONAL_MULTI\|ARG_POSITIONAL_DOUBLEDASH\|ARG_OPTION_STACKING\|ARG_RESTRICT_VALUES\|ARG_DEFAULTS_POS\|ARG_LEFTOVERS\|ARGBASH_WRAP\|INCLUDE_PARSING_CODE\|DEFINE_SCRIPT_DIR\|DEFINE_SCRIPT_DIR_GNU\|_DEFINE_SCRIPT_DIR\|ARGBASH_SET_DELIM\|ARGBASH_GO\|ARGBASH_PREPARE\|ARG_TYPE_GROUP\|ARG_TYPE_GROUP_SET\|ARG_USE_ENV\|ARG_USE_PROG\)\s*\((\|$\)' | sed -e 's/#\s*\([[:alnum:]_]*\).*/\1 /' | tr -d '\n\r')"
464464
test -n "$grep_output" && die "Your script contains possible misspelled Argbash macros: $grep_output" 1
465465
fi
466466
if test "$outfname" != '-'

doc/_static/wrapper-output-action.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Contents of '../src' matching '*.m4':
99
collectors.m4: 20 kiB
1010
constants.m4: 0 kiB
1111
default_settings.m4: 0 kiB
12-
docopt.m4: 2 kiB
12+
docopt.m4: 3 kiB
1313
env_vars.m4: 1 kiB
1414
function_generators.m4: 7 kiB
1515
list.m4: 5 kiB
@@ -23,8 +23,8 @@ Contents of '../src' matching '*.m4':
2323
output-strip-none.m4: 0 kiB
2424
output-strip-user-content.m4: 0 kiB
2525
progs.m4: 2 kiB
26-
stuff.m4: 44 kiB
27-
utilities.m4: 10 kiB
26+
stuff.m4: 46 kiB
27+
utilities.m4: 11 kiB
2828
value_validators.m4: 5 kiB
2929
Contents of '../resources/examples' matching '*.m4':
3030
minimal.m4: 0 kiB

doc/guide.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,20 @@ Plus, there are convenience macros:
429429
* Add a line where the directory where the script is running is stored in an environmental variable:
430430
::
431431

432-
DEFINE_SCRIPT_DIR([variable name (optional, default is script_dir)])
432+
DEFINE_SCRIPT_DIR([variable name (optional, default is 'script_dir')])
433433

434434
You can use this variable to e.g. source ``bash`` snippets that are in a known location relative to the script's parent directory.
435435

436+
::
437+
438+
DEFINE_SCRIPT_DIR_GNU([variable name (optional, default is 'script_dir')])
439+
440+
Does the same as ``DEFINE_SCRIPT_DIR``, but it uses the ``readlink -e`` to determine the real script directory by resolving symlinks.
441+
442+
.. warning::
443+
This command is available only on GNU systems, so be very careful with its usage --- it won't work for OSX users, and for users on non-GNU based Linux distributions (s.a. Alpine Linux).
444+
Don't use it unless you need the functionality AND you are sure that the script will be used only on systems with GNU coreutils.
445+
436446
.. _parsing_code:
437447

438448
* Include a file (let's say a ``parse.sh`` file) that is in the same directory during runtime.

docker/Dockerfile.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ENV PROGRAM=argbash
1919
# and coreutils for readlink
2020
RUN apk add --no-cache \
2121
autoconf \
22-
coreutils \
2322
bash
2423

2524
# Install argbash from sources

resources/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ NUL =
33
# SC2015: Note that A && B || C is not if-then-else. C may run when A is true.
44
SHELLCHECK_EXCLUDE_CHECKS_ARGUMENT = -e 2015
55

6-
SHELLCHECK=$(shell shellcheck -V > /dev/null && echo "shellcheck -x $(SHELLCHECK_EXCLUDE_CHECKS_ARGUMENT)")
6+
SHELLCHECK = $(shell shellcheck -V > /dev/null && echo "shellcheck -x $(SHELLCHECK_EXCLUDE_CHECKS_ARGUMENT)")
7+
8+
DEFINE_SCRIPT_DIR_FORM ?= DEFINE_SCRIPT_DIR$(shell readlink -e /dev/null > /dev/null && echo "_GNU")
79

810
M4_SRC = \
911
../src/output-strip-none.m4 \
@@ -64,6 +66,10 @@ MANPAGE = argbash.1.gz
6466
$(GENPARSE): ../src/argbash.m4 $(M4_SRC)
6567
ARGBASH_INTENDED_DESTINATION="$@" bash $(GENPARSE) $< -o argbash.temp && mv argbash.temp $@
6668

69+
# TODO: Figure out how to use the GNU version of DEFINE_SCRIPT_DIR based on autodetection.
70+
../src/argbash.m4.script-dir: ../src/argbash.m4
71+
sed "s/\\bDEFINE_SCRIPT_DIR\\b/$(DEFINE_SCRIPT_DIR_FORM)/" $< > $@
72+
6773
$(A_INIT): ../src/argbash-init.m4 $(GENPARSE)
6874
$(GENPARSE) $< -o $@
6975

src/stuff.m4

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,36 @@ dnl
8888
dnl $1: Name of the holding variable
8989
dnl Taken from: http://stackoverflow.com/a/246128/592892
9090
argbash_api([DEFINE_SCRIPT_DIR], [m4_do(
91+
[[$0($@)]],
92+
[dnl Taken from: http://stackoverflow.com/a/246128/592892
93+
],
94+
[_DEFINE_SCRIPT_DIR([$1], [cd "$(dirname "${BASH_SOURCE[0]}")" && pwd])],
95+
)])
96+
97+
98+
dnl
99+
dnl Does the same as DEFINE_SCRIPT_DIR, but uses 'readlink -e' to follow symlinks.
100+
dnl Works only on GNU systems.
101+
dnl
102+
dnl $1: Name of the holding variable
103+
dnl Taken from: http://stackoverflow.com/a/246128/592892
104+
argbash_api([DEFINE_SCRIPT_DIR_GNU], [m4_do(
105+
[[$0($@)]],
106+
[dnl Taken from: http://stackoverflow.com/a/246128/592892
107+
],
108+
[_DEFINE_SCRIPT_DIR([$1], [cd "$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")" && pwd])],
109+
)])
110+
111+
112+
dnl
113+
dnl $1: Name of the holding variable
114+
dnl $2: Command to find the script dir
115+
argbash_api([_DEFINE_SCRIPT_DIR], [m4_do(
91116
[[$0($@)]],
92117
[m4_define([SCRIPT_DIR_DEFINED])],
93118
[m4_pushdef([_sciptdir], m4_ifnblank([$1], [[$1]], _DEFAULT_SCRIPTDIR))],
94119
[m4_list_append([_OTHER],
95-
m4_quote(_sciptdir[="$(cd "$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")" && pwd)" || die "Couldn't determine the script's running directory, which probably matters, bailing out" 2]))],
120+
m4_quote(_sciptdir[="$($2)" || die "Couldn't determine the script's running directory, which probably matters, bailing out" 2]))],
96121
[m4_popdef([_sciptdir])],
97122
)])
98123

0 commit comments

Comments
 (0)