github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/hack/man-page-checker (about) 1 #!/bin/bash 2 # 3 # man-page-checker - validate and cross-reference man page names 4 # 5 6 die() { 7 echo "$(basename $0): $*" >&2 8 exit 1 9 } 10 11 cd $(dirname $0)/../docs/source/markdown || die "Please run me from top-level libpod dir" 12 13 rc=0 14 15 for md in *.1.md;do 16 # Read the first line after '# NAME' (or '## NAME'). (FIXME: # and ## 17 # are not the same; should we stick to one convention?) 18 # There may be more than one name, e.g. podman-info.1.md has 19 # podman-system-info then another line with podman-info. We 20 # care only about the first. 21 name=$(egrep -A1 '^#* NAME' $md|tail -1|awk '{print $1}' | tr -d \\\\) 22 23 expect=$(basename $md .1.md) 24 if [ "$name" != "$expect" ]; then 25 echo 26 printf "Inconsistent program NAME in %s:\n" $md 27 printf " NAME= %s (expected: %s)\n" $name $expect 28 rc=1 29 fi 30 done 31 32 # Pass 2: compare descriptions. 33 # 34 # Make sure the descriptive text in podman-foo.1.md matches the one 35 # in the table in podman.1.md. podman-remote is not a podman subcommand, 36 # so it is excluded here. 37 for md in $(ls -1 *-*.1.md | grep -v remote);do 38 desc=$(egrep -A1 '^#* NAME' $md|tail -1|sed -e 's/^podman[^ ]\+ - //') 39 40 # podman.1.md has a two-column table; podman-*.1.md all have three. 41 parent=$(echo $md | sed -e 's/^\(.*\)-.*$/\1.1.md/') 42 if [[ $parent =~ "podman-auto" ]]; then 43 # podman-auto-update.1.md is special cased as it's structure differs 44 # from that of other man pages where main and sub-commands split by 45 # dashes. 46 parent="podman.1.md" 47 fi 48 x=3 49 if expr -- "$parent" : ".*-" >/dev/null; then 50 x=4 51 fi 52 53 # Find the descriptive text in the parent man page. 54 # Strip off the final period; let's not warn about such minutia. 55 parent_desc=$(grep $md $parent | awk -F'|' "{print \$$x}" | sed -e 's/^ \+//' -e 's/ \+$//' -e 's/\.$//') 56 57 if [ "$desc" != "$parent_desc" ]; then 58 echo 59 printf "Inconsistent subcommand descriptions:\n" 60 printf " %-32s = '%s'\n" $md "$desc" 61 printf " %-32s = '%s'\n" $parent "$parent_desc" 62 printf "Please ensure that the NAME section of $md\n" 63 printf "matches the subcommand description in $parent\n" 64 rc=1 65 fi 66 done 67 68 # Pass 3: compare synopses. 69 # 70 # Make sure the SYNOPSIS line in podman-foo.1.md reads '**podman foo** ...' 71 for md in *.1.md;do 72 # FIXME: several pages have a multi-line form of SYNOPSIS in which 73 # many or all flags are enumerated. Some of these are trivial 74 # and really should be made into one line (podman-container-exists, 75 # container-prune, others); some are more complicated and I 76 # would still like to see them one-lined (container-runlabel, 77 # image-trust) but I'm not 100% comfortable doing so myself. 78 # To view those: 79 # $ less $(for i in docs/*.1.md;do x=$(grep -A2 '^#* SYNOPSIS' $i|tail -1); if [ -n "$x" ]; then echo $i;fi;done) 80 # 81 synopsis=$(egrep -A1 '^#* SYNOPSIS' $md|tail -1) 82 83 # Command name must be bracketed by double asterisks; options and 84 # arguments are bracketed by single ones. 85 # E.g. '**podman volume inspect** [*options*] *volume*...' 86 # Get the command name, and confirm that it matches the md file name. 87 cmd=$(echo "$synopsis" | sed -e 's/\(.*\)\*\*.*/\1/' | tr -d \*) 88 md_nodash=$(basename "$md" .1.md | tr '-' ' ') 89 if [[ $md_nodash = 'podman auto update' ]]; then 90 # podman-auto-update.1.md is special cased as it's structure differs 91 # from that of other man pages where main and sub-commands split by 92 # dashes. 93 md_nodash='podman auto-update' 94 fi 95 if [ "$cmd" != "$md_nodash" -a "$cmd" != "podman-remote" ]; then 96 echo 97 printf "Inconsistent program name in SYNOPSIS in %s:\n" $md 98 printf " SYNOPSIS = %s (expected: '%s')\n" "$cmd" "$md_nodash" 99 rc=1 100 fi 101 102 # The convention is to use UPPER CASE in 'podman foo --help', 103 # but *lower case bracketed by asterisks* in the man page 104 if expr "$synopsis" : ".*[A-Z]" >/dev/null; then 105 echo 106 printf "Inconsistent capitalization in SYNOPSIS in %s\n" $md 107 printf " '%s' should not contain upper-case characters\n" "$synopsis" 108 rc=1 109 fi 110 111 # (for debugging, and getting a sense of standard conventions) 112 #printf " %-32s ------ '%s'\n" $md "$synopsis" 113 114 # FIXME: some day: run ./bin/podman "args", extract Usage, 115 # strip off [flags] and [options], then compare arguments 116 done 117 118 119 exit $rc