Skip to content

Commit a876f3e

Browse files
Terry HoweTerryHowe
Terry Howe
authored andcommitted
chore: update command generator for versioned docs (oras-project#335)
Created a mapping file in case we need to use a bug fix release to generate the docs. I don't think that will happen often. Signed-off-by: Terry Howe <[email protected]>
1 parent 4ec5e10 commit a876f3e

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

tools/install.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22

3-
TEMPDIR="${1?First argument is temporary directory}"
3+
VERSION="${1?First argument is version to install}"
4+
TEMPDIR="${2?Second argument is temporary directory}"
45

5-
VERSION="1.1.0"
66
OS="$(uname -s | tr A-Z a-z)"
77
ARCH=$(test "$(uname -m)" = 'x86_64' && echo 'amd64' || echo 'arm64')
88

tools/refresh-commands.sh

+39-16
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@
22

33
TEMPDIR=$(mktemp -d)
44
trap 'rm -rf "$TEMPDIR"' EXIT
5-
ORAS_COMMAND=$(./tools/install.sh ${TEMPDIR})
5+
6+
#
7+
# This script generates command documentation by downloading the oras command
8+
# and parsing the help text to generate documentation. It iterates over the
9+
# `versions.json` file to determine the releases that are currently supported.
10+
#
11+
# If there is a fix to the help documentation in a patch version, use the
12+
# `versions-latest` file to specify the patch release for document generation.
13+
#
14+
# For example, If you are generating documentation for `1.2` and you want to
15+
# use `1.2.2` to generate the documentation, put a line in the `versions-latest`
16+
# file `1.2.2`. If there is no line in the `versions-latest` that matches
17+
# the major and minor release `1.2`, then `1.2.0` will be used to generate
18+
# the documentation.
19+
#
20+
map_version() {
21+
grep "^$1" versions-latest || echo "$1.0"
22+
}
623

724
list_commands() {
825
STATE='Usage'
926
IFS=''
10-
# WEIGHT=1
1127
${ORAS_COMMAND} help ${1} | grep -v '^ completion'| while read LINE
1228
do
1329
[[ "${LINE}" == "" ]] && continue
@@ -35,20 +51,27 @@ list_commands() {
3551
done
3652
}
3753

38-
WEIGHT=10
39-
list_commands | while read COMMAND
54+
VERSIONS=$(tr '[]",' ' ' <versions.json)
55+
for VERSION
56+
in ${VERSIONS}
4057
do
41-
RESULT=$(list_commands "${COMMAND}")
42-
if [ -z "${RESULT}" ]
43-
then
44-
./tools/parse.sh ${TEMPDIR} "${COMMAND}" $WEIGHT >docs/commands/oras_$COMMAND.mdx
45-
WEIGHT=$(expr $WEIGHT + 10)
46-
else
47-
for SUBCOMMAND
48-
in ${RESULT}
49-
do
50-
./tools/parse.sh ${TEMPDIR} "${COMMAND} ${SUBCOMMAND}" $WEIGHT >docs/commands/oras_${COMMAND}_${SUBCOMMAND}.mdx
58+
LATEST_VERSION=$(map_version $VERSION)
59+
ORAS_COMMAND=$(./tools/install.sh ${LATEST_VERSION} ${TEMPDIR})
60+
WEIGHT=10
61+
list_commands | while read COMMAND
62+
do
63+
RESULT=$(list_commands "${COMMAND}")
64+
if [ -z "${RESULT}" ]
65+
then
66+
./tools/parse.sh ${TEMPDIR} "${COMMAND}" $WEIGHT >versioned_docs/version-${VERSION}/commands/oras_$COMMAND.mdx
5167
WEIGHT=$(expr $WEIGHT + 10)
52-
done
53-
fi
68+
else
69+
for SUBCOMMAND
70+
in ${RESULT}
71+
do
72+
./tools/parse.sh ${TEMPDIR} "${COMMAND} ${SUBCOMMAND}" $WEIGHT >docs/commands/oras_${COMMAND}_${SUBCOMMAND}.mdx
73+
WEIGHT=$(expr $WEIGHT + 10)
74+
done
75+
fi
76+
done
5477
done

versions-latest

Whitespace-only changes.

0 commit comments

Comments
 (0)