Skip to content

Commit

Permalink
fix missing quoting for variable expansion
Browse files Browse the repository at this point in the history
- add test and fix further quoting issue

npryce#138
  • Loading branch information
Martin Hans authored and halostatue committed Jul 20, 2024
1 parent ef3afbb commit 648a506
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 58 deletions.
11 changes: 6 additions & 5 deletions src/_adr_add_link
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

source=$("$adr_bin_dir/_adr_file" "${1:?SOURCE}")
source=$("$adr_bin_dir"/_adr_file "${1:?SOURCE}")
link_type="${2:?LINK TYPE}"
target=$("$adr_bin_dir/_adr_file" "${3:?TARGET}")

target_title="$("$adr_bin_dir/_adr_title" "$target")"

awk -v link_type="$link_type" -v target="$(basename "$target")" -v target_title="$target_title" '
BEGIN {
BEGIN {
in_status_section=0
}
/^##/ {
Expand All @@ -19,8 +19,8 @@ awk -v link_type="$link_type" -v target="$(basename "$target")" -v target_title=
}
in_status_section=0
}
/^## Status$/ {
in_status_section=1
/^## Status$/ {
in_status_section=1
}
{ print }
' "$source" > "$source.tmp"
Expand All @@ -29,3 +29,4 @@ if [ -e "$source.tmp" ];
then
mv "$source.tmp" "$source"
fi

4 changes: 2 additions & 2 deletions src/_adr_autocomplete
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

cmds=("$@")
available_commands=$( $adr_bin_dir/_adr_commands | sort )
available_commands=$( "$adr_bin_dir"/_adr_commands | sort )

if (( ${#@} <= 2))
then
Expand Down
2 changes: 1 addition & 1 deletion src/_adr_commands
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

for f in $(cd "$adr_bin_dir" && find . -name 'adr-*')
do
Expand Down
2 changes: 1 addition & 1 deletion src/_adr_file
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

"$adr_bin_dir/adr-list" | grep "$1" | head -1
25 changes: 13 additions & 12 deletions src/_adr_generate_graph
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr generate graph [-p LINK_PREFIX] [-e LINK-EXTENSION]
##
## Generates a visualisation of the links between decision records in
## Graphviz format. This can be piped into the graphviz tools to
## Graphviz format. This can be piped into the graphviz tools to
## generate a an image file.
##
##
## Each node in the graph represents a decision record and is linked to
## the decision record document.
## the decision record document.
##
## Options:
##
## -e LINK-EXTENSION
## the file extension of the documents to which generated links refer.
## -e LINK-EXTENSION
## the file extension of the documents to which generated links refer.
## Defaults to `.html`.
##
## -p LINK_PREFIX
##
## -p LINK_PREFIX
## prefix each decision file link with LINK_PREFIX.
##
##
## E.g. to generate a graph visualisation of decision records in SVG format:
##
## adr generate graph | dot -Tsvg > graph.svg
Expand All @@ -35,7 +35,7 @@ link_extension=.html
while getopts e:p: arg
do
case "$arg" in
e)
e)
link_extension="$OPTARG"
;;
p)
Expand All @@ -62,11 +62,11 @@ for f in $("$adr_bin_dir/adr-list")
do
n=$(index "$f")
title="$("$adr_bin_dir/_adr_title" "$f")"

echo " _$n [label=\"$title\"; URL=\"${link_prefix}$(basename "$f" .md)${link_extension}\"];"
if [ "$n" -gt 1 ]
then
echo " _$(($n - 1)) -> _$n [style=\"dotted\", weight=1];"
echo " _$(("$n" - 1)) -> _$n [style=\"dotted\", weight=1];"
fi
done
echo " }"
Expand All @@ -78,3 +78,4 @@ do
done

echo "}"

10 changes: 6 additions & 4 deletions src/_adr_generate_toc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr generate toc [-s] [-i INTRO] [-o OUTRO] [-p LINK_PREFIX]
##
Expand Down Expand Up @@ -42,9 +42,10 @@ cat <<EOF
EOF

if [ ! -z "$intro" ]; then
cat "$intro"
echo
if [ -n "$intro" ]
then
cat "$intro"
echo
fi

for f in $("$adr_bin_dir/adr-list"); do
Expand All @@ -67,3 +68,4 @@ if [ ! -z "$outro" ]; then
echo
cat "$outro"
fi

6 changes: 3 additions & 3 deletions src/_adr_help
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

cmds=("$@")

Expand All @@ -27,10 +27,10 @@ else
else
grep -E '^##' "$cmdexe" | cut -c 4-
fi

# Assumes only two levels of command / subcommand.
subcmds=( $(compgen -G "$adr_bin_dir/_adr_$1_"'*') )

if (( ${#subcmds} > 0 ))
then
echo
Expand Down
3 changes: 2 additions & 1 deletion src/_adr_help_new
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

cat <<ENDHELP
usage: adr new [-n NUMBER] [-s SUPERSEDED] [-l TARGET:LINK:REVERSE-LINK] TITLE_TEXT...
Expand Down Expand Up @@ -55,3 +55,4 @@ E.g. to create a new ADR that supersedes ADRs 3 and 4, and amends ADR 5:
adr new -s 3 -s 4 -l "5:Amends:Amended by" Use Riak CRDTs to cope with scale
ENDHELP

2 changes: 1 addition & 1 deletion src/_adr_links
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

"$adr_bin_dir/_adr_status" "$1" | sed -n -E 's/^(.+) \[.*\]\(0*([1-9][0-9]*).*\)/\2=\1/p'
18 changes: 9 additions & 9 deletions src/_adr_remove_status
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

current_status=${1:?FROM}
file=$("$adr_bin_dir/_adr_file" "${2:?FILE}")

awk -v current_status="$current_status" '
BEGIN {
in_status_section=0
BEGIN {
in_status_section=0
}
/^##/ {
in_status_section=0
/^##/ {
in_status_section=0
}
/^## Status$/ {
in_status_section=1
/^## Status$/ {
in_status_section=1
}
in_status_section && /^\s*$/ {
if (!after_blank) print
after_blank=1
next
}
in_status_section && $0 == current_status {
next
in_status_section && $0 == current_status {
next
}
in_status_section && ! /^\s*$/ {
after_blank=0
Expand Down
4 changes: 2 additions & 2 deletions src/_adr_status
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

awk '
/^## Status/,/^#/ && !/^## Status/ {
/^## Status/,/^#/ && !/^## Status/ {
if (!/^(#|\s*$)/) print
}
' "$("$adr_bin_dir/_adr_file" "$1")"
2 changes: 1 addition & 1 deletion src/_adr_title
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

head -1 "$("$adr_bin_dir/_adr_file" "$1")" | cut -c 3-
4 changes: 2 additions & 2 deletions src/adr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

cmd="$adr_bin_dir/adr-$1"

if [ -x "$cmd" ]
then
"$cmd" "${@:2}"
else
"$adr_bin_dir/adr-help"
"$adr_bin_dir"/adr-help
exit 1
fi
1 change: 1 addition & 0 deletions src/adr-config
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ fi

echo 'adr_bin_dir="'"${adr_bin_dir}"'"'
echo 'adr_template_dir="'"${adr_template_dir}"'"'

8 changes: 4 additions & 4 deletions src/adr-generate
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr generate [REPORT [OPTION ...]]
##
## Generates summary documentation about the architecture decision records
## that is typically fed into the tool chain for publishing a project's
## documentation.
## that is typically fed into the tool chain for publishing a project's
## documentatation.
##
## To list the report types that can be generated, run:
##
Expand All @@ -16,7 +16,7 @@ eval "$("$(dirname "$0")/adr-config")"
##
## adr help generate <report-type>
##
## For example, the following command will run the "toc" (table of contents)
## For example, the following command will run the "toc" (table of contents)
## generator:
##
## adr generate toc
Expand Down
4 changes: 2 additions & 2 deletions src/adr-help
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr help [COMMAND [SUBCOMMAND...]]
##
## If COMMAND and any SUBCOMMANDs are given, displays help for that command.
## If COMMAND and any SUBCOMMANDs are given, displays help for that command.
## Otherwise lists the available commands.
##
## Uses the environment variables ADR_PAGER or PAGER (in that order) to
Expand Down
8 changes: 4 additions & 4 deletions src/adr-init
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr init [DIRECTORY]
##
##
## Initialises the directory of architecture decision records:
##
##
## * creates a subdirectory of the current working directory
## * creates the first ADR in that subdirectory, recording the decision to
## record architectural decisions with ADRs.
##
## If the DIRECTORY is not given, the ADRs are stored in the directory `doc/adr`.

if [ ! -z "$1" ]
if [ -n "$1" ]
then
mkdir -p "$1"
echo "$1" > .adr-dir
Expand Down
2 changes: 1 addition & 1 deletion src/adr-link
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr link SOURCE LINK TARGET REVERSE-LINK
##
Expand Down
2 changes: 1 addition & 1 deletion src/adr-list
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr list
##
Expand Down
2 changes: 1 addition & 1 deletion src/adr-new
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr new [-n NUMBER] [-s SUPERSEDED] [-l TARGET:LINK:REVERSE-LINK] TITLE_TEXT...
##
Expand Down
2 changes: 1 addition & 1 deletion src/adr-upgrade-repository
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
eval "$("$(dirname "$0")/adr-config")"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr upgrade-repository
##
Expand Down
2 changes: 2 additions & 0 deletions tests/init-with-spaces-in-directory.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
adr init "test doc/adr"
test doc/adr/0001-record-architecture-decisions.md
1 change: 1 addition & 0 deletions tests/init-with-spaces-in-directory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adr init "test doc/adr"

0 comments on commit 648a506

Please sign in to comment.