Merge pull request #2486 from edsantiago/podman_command_compare

podman-commands script: refactor
This commit is contained in:
Ed Santiago
2019-03-01 09:54:45 -07:00
committed by GitHub
2 changed files with 75 additions and 34 deletions

View File

@ -519,7 +519,6 @@ func scrubServer(server string) string {
func UsageTemplate() string { func UsageTemplate() string {
return `Usage:{{if .Runnable}} return `Usage:{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}} {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
Aliases: Aliases:

View File

@ -1,40 +1,82 @@
#!/bin/sh #!/bin/bash
./bin/podman --help | sed -n -Ee '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman.cmd #
man ./docs/podman.1 | sed -n -e '0,/COMMANDS/d' -e '/^FILES/q;p' | grep podman | cut -f2 -d- | cut -f1 -d\( > /tmp/podman.man # Compare commands listed by 'podman help' against those in 'man podman'.
echo diff -B -u /tmp/podman.cmd /tmp/podman.man # Recurse into subcommands as well.
diff -B -u /tmp/podman.cmd /tmp/podman.man #
# Because we read metadoc files in the `docs` directory, this script
# must run from the top level of a git checkout. FIXME: if necessary,
# it could instead run 'man podman-XX'; my thinking is that this
# script should run early in CI.
#
./bin/podman image --help | sed -n -e '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman-image.cmd # override with, e.g., PODMAN=./bin/podman-remote
man ./docs/podman-image.1 | sed -n -Ee '0,/COMMANDS/d' -e 's/^[[:space:]]*//' -e '/^SEE ALSO/q;p' | grep podman | cut -f1 -d' ' | sed 's/^.//' > /tmp/podman-image.man PODMAN=${PODMAN:-./bin/podman}
echo diff -B -u /tmp/podman-image.cmd /tmp/podman-image.man
diff -B -u /tmp/podman-image.cmd /tmp/podman-image.man
./bin/podman container --help | sed -n -e '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman-container.cmd function die() {
man docs/podman-container.1 | sed -n -Ee '0,/COMMANDS/d' -e 's/^[[:space:]]*//' -e '/^SEE ALSO/q;p' | grep podman | cut -f1 -d' ' | sed 's/^.//' > /tmp/podman-container.man echo "FATAL: $*" >&2
echo diff -B -u /tmp/podman-container.cmd /tmp/podman-container.man exit 1
diff -B -u /tmp/podman-container.cmd /tmp/podman-container.man }
./bin/podman system --help | sed -n -e '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman-system.cmd
man docs/podman-system.1 | sed -n -Ee '0,/COMMANDS/d' -e 's/^[[:space:]]*//' -e '/^SEE ALSO/q;p' | grep podman | cut -f1 -d' ' | sed 's/^.//' > /tmp/podman-system.man
echo diff -B -u /tmp/podman-system.cmd /tmp/podman-system.man
diff -B -u /tmp/podman-system.cmd /tmp/podman-system.man
./bin/podman play --help | sed -n -e '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman-play.cmd # Run 'podman help' (possibly against a subcommand, e.g. 'podman help image')
man docs/podman-play.1 | sed -n -Ee '0,/COMMANDS/d' -e 's/^[[:space:]]*//' -e '/^SEE ALSO/q;p' | grep podman | cut -f1 -d' ' | sed 's/^.//' > /tmp/podman-play.man # and return a list of each first word under 'Available Commands', that is,
echo diff -B -u /tmp/podman-play.cmd /tmp/podman-play.man # the command name but not its description.
diff -B -u /tmp/podman-play.cmd /tmp/podman-play.man function podman_commands() {
$PODMAN help "$@" |\
awk '/^Available Commands:/{ok=1;next}/^Flags:/{ok=0}ok { print $1 }' |\
grep .
}
./bin/podman generate --help | sed -n -e '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman-generate.cmd # Read a list of subcommands from a command's metadoc
man docs/podman-generate.1 | sed -n -Ee '0,/COMMANDS/d' -e 's/^[[:space:]]*//' -e '/^SEE ALSO/q;p' | grep podman | cut -f1 -d' ' | sed 's/^.//' > /tmp/podman-generate.man function podman_man() {
echo diff -B -u /tmp/podman-generate.cmd /tmp/podman-generate.man if [ "$@" = "podman" ]; then
diff -B -u /tmp/podman-generate.cmd /tmp/podman-generate.man # podman itself.
# This md file has a table of the form:
# | [podman-cmd(1)\[(podman-cmd.1.md) | Description ... |
# For all such, print the 'cmd' portion (the one in brackets).
sed -ne 's/^|\s\+\[podman-\([a-z]\+\)(1.*/\1/p' <docs/$1.1.md
elif [ "$@" = "podman-image-trust" ]; then
# Special case: set and show aren't actually in a table in the man page
echo set
echo show
else
# podman subcommand.
# Each md file has a table of the form:
# | cmd | [podman-cmd(1)](podman-cmd.1.md) | Description ... |
# For all such we find, with 'podman- in the second column, print the
# first column (with whitespace trimmed)
awk -F\| '$3 ~ /podman-/ { gsub(" ","",$2); print $2 }' < docs/$1.1.md
fi
}
./bin/podman pod --help | sed -n -e '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman-pod.cmd # The main thing. Compares help and man page; if we find subcommands, recurse.
man docs/podman-pod.1 | sed -n -Ee '0,/COMMANDS/d' -e 's/^[[:space:]]*//' -e '/^SEE ALSO/q;p' | grep podman | cut -f1 -d' ' | sed 's/^.//' > /tmp/podman-pod.man rc=0
echo diff -B -u /tmp/podman-pod.cmd /tmp/podman-pod.man function compare_help_and_man() {
diff -B -u /tmp/podman-pod.cmd /tmp/podman-pod.man echo
echo "checking: podman $@"
./bin/podman volume --help | sed -n -e '0,/Available Commands/d' -e '/^Flags/q;p' | sed '/^$/d' | awk '{ print $1 }' > /tmp/podman-volume.cmd # e.g. podman, podman-image, podman-volume
man docs/podman-volume.1 | sed -n -Ee '0,/COMMANDS/d' -e 's/^[[:space:]]*//' -e '/^SEE ALSO/q;p' | grep podman | cut -f1 -d' ' | sed 's/^.//' > /tmp/podman-volume.man local basename=$(echo podman "$@" | sed -e 's/ /-/g')
echo diff -B -u /tmp/podman-volume.cmd /tmp/podman-volume.man
diff -B -u /tmp/podman-volume.cmd /tmp/podman-volume.man podman_commands "$@" | sort > /tmp/${basename}_help.txt
podman_man $basename | sort > /tmp/${basename}_man.txt
diff -u /tmp/${basename}_help.txt /tmp/${basename}_man.txt || rc=1
# Now look for subcommands, e.g. container, image
for cmd in $(< /tmp/${basename}_help.txt); do
usage=$($PODMAN "$@" $cmd --help | grep -A1 '^Usage:' | tail -1)
# if string ends in '[command]', recurse into its subcommands
if expr "$usage" : '.*\[command\]$' >/dev/null; then
compare_help_and_man "$@" $cmd
fi
done
rm -f /tmp/${basename}_{help,man}.txt
}
compare_help_and_man
exit $rc