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

chore: update command generator for versioned docs #335

Merged
Merged
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
4 changes: 2 additions & 2 deletions tools/install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

TEMPDIR="${1?First argument is temporary directory}"
VERSION="${1?First argument is version to install}"
TEMPDIR="${2?Second argument is temporary directory}"

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

Expand Down
55 changes: 39 additions & 16 deletions tools/refresh-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

TEMPDIR=$(mktemp -d)
trap 'rm -rf "$TEMPDIR"' EXIT
ORAS_COMMAND=$(./tools/install.sh ${TEMPDIR})

#
# This script generates command documentation by downloading the oras command
# and parsing the help text to generate documentation. It iterates over the
# `versions.json` file to determine the releases that are currently supported.
#
# If there is a fix to the help documentation in a patch version, use the
# `versions-latest` file to specify the patch release for document generation.
#
# For example, If you are generating documentation for `1.2` and you want to
# use `1.2.2` to generate the documentation, put a line in the `versions-latest`
# file `1.2.2`. If there is no line in the `versions-latest` that matches
# the major and minor release `1.2`, then `1.2.0` will be used to generate
# the documentation.
#
map_version() {
grep "^$1" versions-latest || echo "$1.0"
}

list_commands() {
STATE='Usage'
IFS=''
# WEIGHT=1
${ORAS_COMMAND} help ${1} | grep -v '^ completion'| while read LINE
do
[[ "${LINE}" == "" ]] && continue
Expand Down Expand Up @@ -35,20 +51,27 @@ list_commands() {
done
}

WEIGHT=10
list_commands | while read COMMAND
VERSIONS=$(tr '[]",' ' ' <versions.json)
for VERSION
in ${VERSIONS}
do
RESULT=$(list_commands "${COMMAND}")
if [ -z "${RESULT}" ]
then
./tools/parse.sh ${TEMPDIR} "${COMMAND}" $WEIGHT >docs/commands/oras_$COMMAND.mdx
WEIGHT=$(expr $WEIGHT + 10)
else
for SUBCOMMAND
in ${RESULT}
do
./tools/parse.sh ${TEMPDIR} "${COMMAND} ${SUBCOMMAND}" $WEIGHT >docs/commands/oras_${COMMAND}_${SUBCOMMAND}.mdx
LATEST_VERSION=$(map_version $VERSION)
ORAS_COMMAND=$(./tools/install.sh ${LATEST_VERSION} ${TEMPDIR})
WEIGHT=10
list_commands | while read COMMAND
do
RESULT=$(list_commands "${COMMAND}")
if [ -z "${RESULT}" ]
then
./tools/parse.sh ${TEMPDIR} "${COMMAND}" $WEIGHT >versioned_docs/version-${VERSION}/commands/oras_$COMMAND.mdx
WEIGHT=$(expr $WEIGHT + 10)
done
fi
else
for SUBCOMMAND
in ${RESULT}
do
./tools/parse.sh ${TEMPDIR} "${COMMAND} ${SUBCOMMAND}" $WEIGHT >docs/commands/oras_${COMMAND}_${SUBCOMMAND}.mdx
WEIGHT=$(expr $WEIGHT + 10)
done
fi
done
done
Empty file added versions-latest
Empty file.