-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow lower level subcommands (#439)
The current command document generator only does two levels of commands. The introduction of `oras manifest index create` is three levels. While this PR is a bit tough to look at, the actual code is a lot easier to look at. * Broke out `list_command.sh` into a shell script that can be run and tested by itself for example `./tools/list_command manifest index` * Simplified the path to the current `oras` command so it doesn't need to be passed around * Simplified temp file handling * Created `subcommands.sh` that either prints the command or iterates through the subcommands which can be run for example `./tools/subcommands.sh manifest ./versioned_docs/version-1.3.0-beta.1/commands ` --------- Signed-off-by: Terry Howe <[email protected]>
- Loading branch information
Showing
5 changed files
with
71 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
COMMAND="${1?First argument is command}" | ||
|
||
STATE='Usage' | ||
oras help ${COMMAND} | grep -v '^ completion'| while read LINE | ||
do | ||
[[ "${LINE}" == "" ]] && continue | ||
|
||
case "${STATE}" in | ||
Usage) | ||
if [[ "${LINE}" == Available* ]] | ||
then | ||
STATE='Commands' | ||
continue | ||
fi | ||
;; | ||
Commands) | ||
if [[ "${LINE}" == Flags* ]] | ||
then | ||
STATE='Flags' | ||
continue | ||
fi | ||
COMMAND=$(echo "${LINE}" | sed -e 's/^[[:space:]]*//' | sed -e 's/[[:space:]].*//') | ||
echo ${COMMAND} | ||
;; | ||
Flags) | ||
;; | ||
esac | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
COMMAND="${1?First argument is command}" | ||
DESTINATION="${2?Second argument is destination directory}" | ||
|
||
TEMPDIR=$(mktemp -d) | ||
trap 'rm -rf "$TEMPDIR"' EXIT | ||
WEIGHT_FILE="${3}" | ||
if [ "${WEIGHT_FILE}" == "" ] | ||
then | ||
WEIGHT_FILE="${3:-${TEMPDIR}/weight}" | ||
echo 10 >${WEIGHT_FILE} | ||
fi | ||
|
||
./tools/list_commands.sh "${COMMAND}" "${DESTINATION}" >"${TEMPDIR}/subcommands" | ||
if [ ! -s "${TEMPDIR}/subcommands" ] | ||
then | ||
WEIGHT=$(cat $WEIGHT_FILE) | ||
FILE="${DESTINATION}/oras_$(echo ${COMMAND} | sed -e 's/ /_/g').mdx" | ||
./tools/parse.sh "${COMMAND}" "$WEIGHT" >"${FILE}" | ||
if ! git diff --quiet "${FILE}" | ||
then | ||
echo "** Updated ${FILE} **" | ||
fi | ||
echo $(expr $WEIGHT + 10) >${WEIGHT_FILE} | ||
exit 0 | ||
fi | ||
while read SUBCOMMAND | ||
do | ||
./tools/subcommands.sh "$(echo ${COMMAND} ${SUBCOMMAND})" "${DESTINATION}" "${WEIGHT_FILE}" | ||
done <"${TEMPDIR}/subcommands" |