From ca893b83293e895d2dbd27f6fa287e396368d3bc Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Mon, 10 Aug 2020 08:39:06 -0600 Subject: Man pages: assert that subcommands are in order For each podman*.md file with a subcommand table (podman, podman-container, etc), assert that the subcommand list is sorted. Change is bigger than it should be, because it switches from nice clean local per-function error counting to using a nasty global. Signed-off-by: Ed Santiago --- hack/xref-helpmsgs-manpages | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/hack/xref-helpmsgs-manpages b/hack/xref-helpmsgs-manpages index 16b596589..fd8fe152d 100755 --- a/hack/xref-helpmsgs-manpages +++ b/hack/xref-helpmsgs-manpages @@ -29,6 +29,9 @@ my $PODMAN = $ENV{PODMAN} || $Default_Podman; # Path to podman markdown source files (of the form podman-*.1.md) my $Markdown_Path = 'docs/source/markdown'; +# Global error count +my $Errs = 0; + # END user-customizable section ############################################################################### @@ -97,10 +100,10 @@ sub main { my $help = podman_help(); my $man = podman_man('podman'); - my $retval = xref_by_help($help, $man) - + xref_by_man($help, $man); + xref_by_help($help, $man); + xref_by_man($help, $man); - exit !!$retval; + exit !!$Errs; } ################## @@ -108,23 +111,20 @@ sub main { ################## sub xref_by_help { my ($help, $man, @subcommand) = @_; - my $errs = 0; for my $k (sort keys %$help) { if (exists $man->{$k}) { if (ref $help->{$k}) { - $errs += xref_by_help($help->{$k}, $man->{$k}, @subcommand, $k); + xref_by_help($help->{$k}, $man->{$k}, @subcommand, $k); } # Otherwise, non-ref is leaf node such as a --option } else { my $man = $man->{_path} || 'man'; warn "$ME: podman @subcommand --help lists $k, but $k not in $man\n"; - ++$errs; + ++$Errs; } } - - return $errs; } ################# @@ -137,13 +137,11 @@ sub xref_by_help { sub xref_by_man { my ($help, $man, @subcommand) = @_; - my $errs = 0; - # FIXME: this generates way too much output for my $k (grep { $_ ne '_path' } sort keys %$man) { if (exists $help->{$k}) { if (ref $man->{$k}) { - $errs += xref_by_man($help->{$k}, $man->{$k}, @subcommand, $k); + xref_by_man($help->{$k}, $man->{$k}, @subcommand, $k); } } elsif ($k ne '--help' && $k ne '-h') { @@ -175,11 +173,9 @@ sub xref_by_man { next if "@subcommand" eq 'system' && $k eq 'service'; warn "$ME: podman @subcommand: $k in $man, but not --help\n"; - ++$errs; + ++$Errs; } } - - return $errs; } @@ -249,6 +245,7 @@ sub podman_man { or die "$ME: Cannot read $manpath: $!\n"; my $section = ''; my @most_recent_flags; + my $previous_subcmd = ''; while (my $line = <$fh>) { chomp $line; next unless $line; # skip empty lines @@ -278,6 +275,11 @@ sub podman_man { elsif ($line =~ /^\|\s+(\S+)\s+\|\s+\[\S+\]\((\S+)\.1\.md\)/) { # $1 will be changed by recursion _*BEFORE*_ left-hand assignment my $subcmd = $1; + if ($previous_subcmd gt $subcmd) { + warn "$ME: $subpath: '$previous_subcmd' and '$subcmd' are out of order\n"; + ++$Errs; + } + $previous_subcmd = $subcmd; $man{$subcmd} = podman_man($2); } } -- cgit v1.2.3-54-g00ecf From 8e11a825e18a571ca8fd624ce0053682b238133f Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Mon, 10 Aug 2020 13:34:24 -0600 Subject: Cross-reference *.rst files too There are a bunch of *.rst files in docs/source, linking sometimes to man pages and sometimes to other .rst files. These files each have entries of the following form: :doc:`foo ` Description of foo ...for all podman sub and sub-subcommands 'foo'. Read all .rst files and make sure that: - all entries in a given file are in alphabetical order - all link-to-foo targets point to existing doc files - every subcommand known by 'podman help' has a corresponding doc entry in a .rst file Signed-off-by: Ed Santiago --- docs/source/Commands.rst | 2 +- docs/source/image.rst | 6 +-- docs/source/managecontainers.rst | 4 +- docs/source/system.rst | 2 +- hack/xref-helpmsgs-manpages | 110 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 116 insertions(+), 8 deletions(-) diff --git a/docs/source/Commands.rst b/docs/source/Commands.rst index a3ff24e89..096bdbedf 100644 --- a/docs/source/Commands.rst +++ b/docs/source/Commands.rst @@ -98,7 +98,7 @@ Commands :doc:`top ` Display the running processes of a container -:doc:`umount ` Unmounts working container's root filesystem +:doc:`unmount ` Unmounts working container's root filesystem :doc:`unpause ` Unpause the processes in one or more containers diff --git a/docs/source/image.rst b/docs/source/image.rst index fe3a7aa3b..2b0ef3d43 100644 --- a/docs/source/image.rst +++ b/docs/source/image.rst @@ -18,7 +18,7 @@ Image :doc:`load ` Load an image from container archive -:doc:`mount ` Mount an image's root filesystem. +:doc:`mount ` Mount an image's root filesystem. :doc:`prune ` Remove unused images @@ -40,6 +40,6 @@ Image :doc:`trust ` Manage container image trust policy -:doc:`untag ` Removes one or more names from a locally-stored image - :doc:`unmount ` Unmount an image's root filesystem + +:doc:`untag ` Removes one or more names from a locally-stored image diff --git a/docs/source/managecontainers.rst b/docs/source/managecontainers.rst index 2e787c9e9..849fd1d25 100644 --- a/docs/source/managecontainers.rst +++ b/docs/source/managecontainers.rst @@ -37,10 +37,10 @@ Manage Containers :doc:`port ` List port mappings or a specific mapping for the container -:doc:`restart ` Restart one or more containers - :doc:`prune ` Remove all stopped containers +:doc:`restart ` Restart one or more containers + :doc:`restore ` Restores one or more containers from a checkpoint :doc:`rm ` Remove one or more containers diff --git a/docs/source/system.rst b/docs/source/system.rst index e3dfa9d01..566fd1a95 100644 --- a/docs/source/system.rst +++ b/docs/source/system.rst @@ -1,7 +1,7 @@ System ====== -:doc:`connection ` Manage the destination(s) for Podman service(s) +:doc:`connection ` Manage the destination(s) for Podman service(s) :doc:`df ` Show podman disk usage diff --git a/hack/xref-helpmsgs-manpages b/hack/xref-helpmsgs-manpages index fd8fe152d..7b617eed7 100755 --- a/hack/xref-helpmsgs-manpages +++ b/hack/xref-helpmsgs-manpages @@ -26,8 +26,11 @@ $| = 1; my $Default_Podman = './bin/podman'; my $PODMAN = $ENV{PODMAN} || $Default_Podman; +# Path to all doc files, including .rst and (down one level) markdown +my $Docs_Path = 'docs/source'; + # Path to podman markdown source files (of the form podman-*.1.md) -my $Markdown_Path = 'docs/source/markdown'; +my $Markdown_Path = "$Docs_Path/markdown"; # Global error count my $Errs = 0; @@ -99,13 +102,19 @@ sub main { my $help = podman_help(); my $man = podman_man('podman'); + my $rst = podman_rst(); xref_by_help($help, $man); xref_by_man($help, $man); + xref_rst($help, $rst); + exit !!$Errs; } +############################################################################### +# BEGIN cross-referencing + ################## # xref_by_help # Find keys in '--help' but not in man ################## @@ -178,6 +187,33 @@ sub xref_by_man { } } +############## +# xref_rst # Cross-check *.rst files against help +############## +sub xref_rst { + my ($help, $rst, @subcommand) = @_; + + # Cross-check against rst (but only subcommands, not options). + # We key on $help because that is Absolute Truth: anything in podman --help + # must be referenced in an rst (the converse is not true). + for my $k (sort grep { $_ !~ /^-/ } keys %$help) { + # Check for subcommands, if any (eg podman system -> connection -> add) + if (ref $help->{$k}) { + xref_rst($help->{$k}, $rst->{$k}, @subcommand, $k); + } + + # Check that command is mentioned in at least one .rst file + if (! exists $rst->{$k}{_desc}) { + my @podman = ("podman", @subcommand, $k); + warn "$ME: no link in *.rst for @podman\n"; + ++$Errs; + } + } +} + +# END cross-referencing +############################################################################### +# BEGIN data gathering ################# # podman_help # Parse output of 'podman [subcommand] --help' @@ -317,4 +353,76 @@ sub podman_man { } +################ +# podman_rst # Parse contents of docs/source/*.rst +################ +sub podman_rst { + my %rst; + + # Read all .rst files, looking for ":doc:`subcmd ` description" + for my $rst (glob "$Docs_Path/*.rst") { + open my $fh, '<', $rst + or die "$ME: Cannot read $rst: $!\n"; + + # The basename of foo.rst is usually, but not always, the name of + # a podman subcommand. There are a few special cases: + (my $command = $rst) =~ s!^.*/(.*)\.rst!$1!; + + my $subcommand_href = \%rst; + if ($command eq 'Commands') { + ; + } + elsif ($command eq 'managecontainers') { + $subcommand_href = $rst{container} //= { }; + } + elsif ($command eq 'connection') { + $subcommand_href = $rst{system}{connection} //= { }; + } + else { + $subcommand_href = $rst{$command} //= { }; + } + + my $previous_subcommand = ''; + while (my $line = <$fh>) { + if ($line =~ /^:doc:`(\S+)\s+<(.*?)>`\s+(.*)/) { + my ($subcommand, $target, $desc) = ($1, $2, $3); + + # Check that entries are in alphabetical order + if ($subcommand lt $previous_subcommand) { + warn "$ME: $rst:$.: '$previous_subcommand' and '$subcommand' are out of order\n"; + ++$Errs; + } + $previous_subcommand = $subcommand; + + # Mark this subcommand as documented. + $subcommand_href->{$subcommand}{_desc} = $desc; + + # Check for invalid links. These will be one of two forms: + # -> markdown/foo.1.md + # -> foo.rst + if ($target =~ m!^markdown/!) { + if (! -e "$Docs_Path/$target.md") { + warn "$ME: $rst:$.: '$subcommand' links to nonexistent $target\n"; + ++$Errs; + } + } + else { + if (! -e "$Docs_Path/$target.rst") { + warn "$ME: $rst:$.: '$subcommand' links to nonexistent $target.rst\n"; + } + } + } + } + close $fh; + } + + # Special case: 'image trust set/show' are documented in image-trust.1 + $rst{image}{trust}{$_} = { _desc => 'ok' } for (qw(set show)); + + return \%rst; +} + +# END data gathering +############################################################################### + 1; -- cgit v1.2.3-54-g00ecf