Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quoting #138

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/_adr_add_link
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/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 Down
4 changes: 2 additions & 2 deletions src/_adr_autocomplete
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/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 @@
#!/bin/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
12 changes: 6 additions & 6 deletions src/_adr_dir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"
eval "$("$(dirname $0)"/adr-config)"

reldir=.

Expand All @@ -10,16 +10,16 @@ function mkrel() {
}

function absdir() {
(cd $(dirname $1) && pwd -P)
(cd "$(dirname $1)" && pwd -P)
}

while [ $(absdir $reldir) != / ]
while [ "$(absdir $reldir)" != / ]
do
if [ -f $(mkrel .adr-dir) ]
if [ -f "$(mkrel .adr-dir)" ]
then
mkrel $(cat $(mkrel .adr-dir))
mkrel "$(cat "$(mkrel .adr-dir)")"
exit
elif [ -d $(mkrel doc/adr) ]
elif [ -d "$(mkrel doc/adr)" ]
then
mkrel doc/adr
exit
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 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"
eval "$("$(dirname $0)"/adr-config)"

"$adr_bin_dir/adr-list" | grep "$1" | head -1
30 changes: 15 additions & 15 deletions src/_adr_generate_graph
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/bin/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 @@ -61,12 +61,12 @@ echo " subgraph {"
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 ]
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 Down
8 changes: 4 additions & 4 deletions src/_adr_generate_toc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"
eval "$("$(dirname $0)"/adr-config)"

## usage: adr generate toc [-i INTRO] [-o OUTRO] [-p LINK_PREFIX]
##
Expand All @@ -10,12 +10,12 @@ eval "$($(dirname $0)/adr-config)"
##
## -i INTRO precede the table of contents with the given INTRO text.
## -o OUTRO follow the table of contents with the given OUTRO text.
## -p LINK_PREFIX
## -p LINK_PREFIX
## prefix each decision file link with LINK_PREFIX.
##
## Both INTRO and OUTRO must be in Markdown format.

args=$(getopt i:o:p: $*)
args=$(getopt i:o:p: "$@")
set -- $args

link_prefix=
Expand Down Expand Up @@ -48,7 +48,7 @@ cat <<EOF

EOF

if [ ! -z $intro ]
if [ -n "$intro" ]
then
cat "$intro"
echo
Expand Down
6 changes: 3 additions & 3 deletions src/_adr_help
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/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
10 changes: 5 additions & 5 deletions src/_adr_help_new
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"
eval "$("$(dirname "$0")"/adr-config)"

cat <<ENDHELP
usage: adr new [-s SUPERCEDED] [-l TARGET:LINK:REVERSE-LINK] TITLE_TEXT...
Expand Down Expand Up @@ -30,14 +30,14 @@ Options:
it has been superceded by the new ADR.

-l TARGET:LINK:REVERSE-LINK
Links the new ADR to a previous ADR.
TARGET is a reference (number or partial filename) of a
previous decision.
Links the new ADR to a previous ADR.
TARGET is a reference (number or partial filename) of a
previous decision.
LINK is the description of the link created in the new ADR.
REVERSE-LINK is the description of the link created in the
existing ADR that will refer to the new ADR.

Multiple -s and -l options can be given, so that the new ADR can supercede
Multiple -s and -l options can be given, so that the new ADR can supercede
or link to multiple existing ADRs.

E.g. to create a new ADR with the title "Use MySQL Database":
Expand Down
2 changes: 1 addition & 1 deletion src/_adr_links
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/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 @@
#!/bin/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 @@
#!/bin/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")"
4 changes: 2 additions & 2 deletions src/_adr_title
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"
eval "$("$(dirname "$0")"/adr-config)"

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

cmd=$adr_bin_dir/adr-$1

if [ -x $cmd ]
if [ -x "$cmd" ]
then
$cmd "${@:2}"
else
$adr_bin_dir/adr-help
"$adr_bin_dir"/adr-help
exit 1
fi
2 changes: 1 addition & 1 deletion src/adr-config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Config for when running from the source directory.

basedir=$(cd -L $(dirname $0) >/dev/null 2>&1 && pwd -L)
basedir=$(cd -L "$(dirname "$0")" >/dev/null 2>&1 && pwd -L)

echo 'adr_bin_dir="'"${basedir}"'"'
echo 'adr_template_dir="'"${basedir}"'"'
8 changes: 4 additions & 4 deletions src/adr-generate
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/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
## 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 All @@ -27,7 +27,7 @@ eval "$($(dirname $0)/adr-config)"

cmd=$1

if [ -z $cmd ]
if [ -z "$cmd" ]
then
(cd "$adr_bin_dir" && find . -name '_adr_generate_*') | cut -c 17-
else
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 @@
#!/bin/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 @@
#!/bin/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 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"
eval "$("$(dirname "$0")"/adr-config)"

## usage: adr link SOURCE LINK TARGET REVERSE-LINK
##
Expand Down
Loading