|
2 | 2 |
|
3 | 3 | TEMPDIR=$(mktemp -d)
|
4 | 4 | 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 | +} |
6 | 23 |
|
7 | 24 | list_commands() {
|
8 | 25 | STATE='Usage'
|
9 | 26 | IFS=''
|
10 |
| - # WEIGHT=1 |
11 | 27 | ${ORAS_COMMAND} help ${1} | grep -v '^ completion'| while read LINE
|
12 | 28 | do
|
13 | 29 | [[ "${LINE}" == "" ]] && continue
|
@@ -35,20 +51,27 @@ list_commands() {
|
35 | 51 | done
|
36 | 52 | }
|
37 | 53 |
|
38 |
| -WEIGHT=10 |
39 |
| -list_commands | while read COMMAND |
| 54 | +VERSIONS=$(tr '[]",' ' ' <versions.json) |
| 55 | +for VERSION |
| 56 | +in ${VERSIONS} |
40 | 57 | 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 |
51 | 67 | 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 |
54 | 77 | done
|
0 commit comments