Skip to content

Commit

Permalink
Make -p LINK_PREFIX command line option consistent for generate toc a…
Browse files Browse the repository at this point in the history
…nd graph
  • Loading branch information
npryce committed Jun 28, 2018
1 parent 89f1c88 commit 060bf43
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
19 changes: 10 additions & 9 deletions src/_adr_generate_graph
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
eval "$($(dirname $0)/adr-config)"

## usage: adr generate graph [-e LINK-EXTENSION]
## 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
Expand All @@ -14,10 +14,11 @@ eval "$($(dirname $0)/adr-config)"
## Options:
##
## -e LINK-EXTENSION
## The file extension of the documents to which generated links refer.
## the file extension of the documents to which generated links refer.
## Defaults to `.html`.
##
## -r ROOT The root to preppend to the document file names in links.
##
## -p LINK_PREFIX
## prefix each decision file link with LINK_PREFIX.
##
## E.g. to generate a graph visualisation of decision records in SVG format:
##
Expand All @@ -28,17 +29,17 @@ eval "$($(dirname $0)/adr-config)"
##
## adr generate graph -e .pdf | dot -Tpdf > graph.pdf

link_root=
link_prefix=
link_extension=.html

while getopts e:r: arg
while getopts e:p: arg
do
case "$arg" in
e)
link_extension="$OPTARG"
;;
r)
link_root="$OPTARG"
p)
link_prefix="$OPTARG"
;;
*)
echo "Not implemented: $arg" >&2
Expand All @@ -61,7 +62,7 @@ do
n=$(index "$f")
title=$("$adr_bin_dir/_adr_title" $f)

echo " _$n [label=\"$title\"; URL=\"${link_root}$(basename $f .md)${link_extension}\"]"
echo " _$n [label=\"$title\"; URL=\"${link_prefix}$(basename $f .md)${link_extension}\"]"
if [ $n -gt 1 ]
then
echo " _$(($n - 1)) -> _$n [style=\"dotted\"];"
Expand Down
11 changes: 7 additions & 4 deletions src/_adr_generate_toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
set -e
eval "$($(dirname $0)/adr-config)"

## usage: adr generate toc [-i INTRO] [-o OUTRO] [-p PATH]
## usage: adr generate toc [-i INTRO] [-o OUTRO] [-p LINK_PREFIX]
##
## Generates a table of contents in Markdown format to stdout.
##
## Options:
##
## -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 PATH prefix each decision file link with the given PATH.
## -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: $*)
set -- $args

link_prefix=

for arg
do
case "$arg"
Expand All @@ -30,7 +33,7 @@ do
shift 2
;;
-p)
path_prefix="$2"
link_prefix="$2"
shift 2
;;
--)
Expand All @@ -54,7 +57,7 @@ fi
for f in $("$adr_bin_dir/adr-list")
do
title=$("$adr_bin_dir/_adr_title" $f)
link=$([ ! -z $path_prefix ] && echo "$path_prefix/")$(basename $f)
link=${link_prefix}$(basename $f)

echo "* [$title]($link)"
done
Expand Down
2 changes: 1 addition & 1 deletion tests/generate-contents-with-prefix.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ adr new Second Decision
doc/adr/0002-second-decision.md
adr new Third Decision
doc/adr/0003-third-decision.md
adr generate toc -p foo/doc/adr
adr generate toc -p foo/doc/adr/
# Architecture Decision Records

* [1. First Decision](foo/doc/adr/0001-first-decision.md)
Expand Down
2 changes: 1 addition & 1 deletion tests/generate-contents-with-prefix.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
adr new First Decision
adr new Second Decision
adr new Third Decision
adr generate toc -p foo/doc/adr
adr generate toc -p foo/doc/adr/
2 changes: 1 addition & 1 deletion tests/generate-graph.expected
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ digraph {
_5 -> _3 [label="Supercedes"]
}
# with specified root and extension in links
adr generate graph -r http://example.com/ -e .xxx
adr generate graph -p http://example.com/ -e .xxx
digraph {
node [shape=plaintext];
_1 [label="1. Record architecture decisions"; URL="http://example.com/0001-record-architecture-decisions.xxx"]
Expand Down
2 changes: 1 addition & 1 deletion tests/generate-graph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ adr new -s 3 The end
# with default root and extension in links
adr generate graph
# with specified root and extension in links
adr generate graph -r http://example.com/ -e .xxx
adr generate graph -p http://example.com/ -e .xxx

0 comments on commit 060bf43

Please sign in to comment.