diff --git a/src/_adr_generate_toc b/src/_adr_generate_toc index fb6e966..df08c39 100755 --- a/src/_adr_generate_toc +++ b/src/_adr_generate_toc @@ -10,15 +10,17 @@ 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. +## -r list the records in reverse order ## ## Both INTRO and OUTRO must be in Markdown format. -args=$(getopt i:o:p: $*) +args=$(getopt i:o:p:r $*) set -- $args link_prefix= +list_args=() for arg do @@ -36,6 +38,10 @@ do link_prefix="$2" shift 2 ;; + -r) + list_args+=("-r") + shift + ;; --) shift break @@ -54,7 +60,7 @@ then echo fi -for f in $("$adr_bin_dir/adr-list") +for f in $("$adr_bin_dir/adr-list" ${list_args[@]}) do title=$("$adr_bin_dir/_adr_title" $f) link=${link_prefix}$(basename $f) diff --git a/src/adr-list b/src/adr-list index 23dd366..1381fa5 100755 --- a/src/adr-list +++ b/src/adr-list @@ -2,15 +2,37 @@ set -e eval "$($(dirname $0)/adr-config)" -## usage: adr list +## usage: adr list [-r] ## ## Lists the architecture decision records +## +## Options: +## +## -r list decision records in reverse order adr_dir=$("$adr_bin_dir/_adr_dir") +sort_args=() + +if (( $# > 0 )); then + while getopts ":r" arg; do + case "${arg}" in + r) + sort_args+=("-r") + ;; + + *) + echo "invalid argument: $OPTARG" >&2 + exit 1 + ;; + esac + done + shift $((OPTIND-1)) +fi + if [ -d $adr_dir ] then - find $adr_dir | grep -E "^$adr_dir/[0-9]+-[^/]*\\.md" | sort + find $adr_dir | grep -E "^$adr_dir/[0-9]+-[^/]*\\.md" | sort ${sort_args[@]} else echo "The $adr_dir directory does not exist" exit 1 diff --git a/tests/generate-contents.expected b/tests/generate-contents.expected index 140687d..37a25c6 100644 --- a/tests/generate-contents.expected +++ b/tests/generate-contents.expected @@ -10,3 +10,9 @@ adr generate toc * [1. First Decision](0001-first-decision.md) * [2. Second Decision](0002-second-decision.md) * [3. Third Decision](0003-third-decision.md) +adr generate toc -r +# Architecture Decision Records + +* [3. Third Decision](0003-third-decision.md) +* [2. Second Decision](0002-second-decision.md) +* [1. First Decision](0001-first-decision.md) diff --git a/tests/generate-contents.sh b/tests/generate-contents.sh index aa3b9e7..ed4d937 100644 --- a/tests/generate-contents.sh +++ b/tests/generate-contents.sh @@ -2,3 +2,4 @@ adr new First Decision adr new Second Decision adr new Third Decision adr generate toc +adr generate toc -r diff --git a/tests/list-records.expected b/tests/list-records.expected index b7d8216..9a97b17 100644 --- a/tests/list-records.expected +++ b/tests/list-records.expected @@ -15,4 +15,7 @@ adr list doc/adr/0001-first.md doc/adr/0002-second.md doc/adr/0003-third.md - +adr list -r +doc/adr/0003-third.md +doc/adr/0002-second.md +doc/adr/0001-first.md diff --git a/tests/list-records.sh b/tests/list-records.sh index 7737137..7be5440 100644 --- a/tests/list-records.sh +++ b/tests/list-records.sh @@ -5,4 +5,4 @@ adr new second adr list adr new third adr list - +adr list -r \ No newline at end of file