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

Switch help messages from using [flags] to [options] #8034

Merged
merged 1 commit into from
Oct 21, 2020

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Oct 15, 2020

Want to have man pages match commands, since we have lots of printed
man pages with using Options, we will change the command line to use
Options in --help.

Signed-off-by: Daniel J Walsh [email protected]

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 15, 2020
@rhatdan rhatdan force-pushed the options branch 8 times, most recently from 71cc292 to cc7521f Compare October 15, 2020 15:34
@TomSweeneyRedHat
Copy link
Member

Looks like you changed Options to Flags everywhere. As other doc says Options, including RHEL doc and our other projects, we should stick with options.

@rhatdan
Copy link
Member Author

rhatdan commented Oct 15, 2020

Well then you have a conflict between cmd which calls them flags. I am not sure if that can be changed, easily in podman help

$ podman version --help
Display the Podman Version Information

Description:
  

Usage:
  podman version [flags]

Flags:
  -f, --format string   Change the output format to JSON or a Go template

@jwhonce jwhonce changed the title Switch help messages from using [flags] to [options] [CI:DOCS] Switch help messages from using [flags] to [options] Oct 15, 2020
Copy link
Member

@jwhonce jwhonce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small issues

@@ -40,7 +40,7 @@ is used.

Any additional arguments will be appended to the command.

## OPTIONS:
## FLAGS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## FLAGS:
## FLAGS

Other pages do not have :

@@ -12,7 +12,7 @@ of a pod or container name or ID.

Note that the generated Kubernetes YAML file can be used to re-run the deployment via podman-play-kube(1).

## OPTIONS:
## FLAGS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## FLAGS:
## FLAGS


## DESCRIPTION
**podman generate systemd** will create a systemd unit file that can be used to control a container or pod.
By default, the command will print the content of the unit files to stdout.

_Note: If you use this command with the remote client, you would still have to place the generated units on the remote system._

## OPTIONS:
## FLAGS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## FLAGS:
## FLAGS

@@ -21,7 +21,7 @@ For more inspection options, see:
podman volume inspect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this list be expanded to include pods and volumes?

@@ -15,7 +15,7 @@ Ideally the input file would be one created by Podman (see podman-generate-kube(

Note: HostPath volume types created by play kube will be given an SELinux private label (Z)

## OPTIONS:
## FLAGS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## FLAGS:
## FLAGS


## DESCRIPTION
Display the running processes of containers in a pod. The *format-descriptors* are ps (1) compatible AIX format descriptors but extended to print additional information, such as the seccomp mode or the effective capabilities of a given process. The descriptors can either be passed as separated arguments or as a single comma-separated argument. Note that you can also specify options and or flags of ps(1); in this case, Podman will fallback to executing ps with the specified arguments and flags in the container.
Display the running processes of containers in a pod. The *format-descriptors* are ps (1) compatible AIX format descriptors but extended to print additional information, such as the seccomp mode or the effective capabilities of a given process. The descriptors can either be passed as separated arguments or as a single comma-separated argument. Note that you can also specify options and or options of ps(1); in this case, Podman will fallback to executing ps with the specified arguments and options in the container.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Display the running processes of containers in a pod. The *format-descriptors* are ps (1) compatible AIX format descriptors but extended to print additional information, such as the seccomp mode or the effective capabilities of a given process. The descriptors can either be passed as separated arguments or as a single comma-separated argument. Note that you can also specify options and or options of ps(1); in this case, Podman will fallback to executing ps with the specified arguments and options in the container.
Display the running processes of containers in a pod. The *format-descriptors* are ps (1) compatible AIX format descriptors but extended to print additional information, such as the seccomp mode or the effective capabilities of a given process. The descriptors can either be passed as separated arguments or as a single comma-separated argument. Note that you can specify options and/or additionally options of ps(1); in this case, Podman will fallback to executing ps with the specified arguments and options in the container.

@jwhonce
Copy link
Member

jwhonce commented Oct 15, 2020

Looks like you changed Options to Flags everywhere. As other doc says Options, including RHEL doc and our other projects, we should stick with options.

I suspect we would need to dig into how to override the whole help generation
https://github.com/spf13/cobra/blob/master/command.go#L1240

@rhatdan rhatdan force-pushed the options branch 2 times, most recently from 43ecd5c to 49ca425 Compare October 15, 2020 19:13
@rhatdan rhatdan changed the title [CI:DOCS] Switch help messages from using [flags] to [options] Switch help messages from using [flags] to [options] Oct 15, 2020
@rhatdan
Copy link
Member Author

rhatdan commented Oct 15, 2020

I fixed the help generation to use Options now. so back to original.
sed 's/flag/option/g' ...

I will need help from @edsantiago to get his tests to pass. test/system/015-help.bats still seems broken.

@rhatdan
Copy link
Member Author

rhatdan commented Oct 15, 2020

BTW we definitely need the tests to run on this. This is not only CI Docs.

@jwhonce
Copy link
Member

jwhonce commented Oct 15, 2020

@rhatdan

At https://github.com/containers/podman/blob/master/cmd/podman/main.go#L69 you may need to add

				c.Command.DisableFlagsInUseLine = true

@edsantiago
Copy link
Member

One reason for [flags] is that Cobra automatically adds that string if it is missing from a help message. That is, if your command has flags-options-whatever, and you do not include the string "[flags]" in the Usage message, Cobra will helpfully add it (usually in the wrong place).

I don't really care whether anyone uses flags or options, but I've had an exhausting day and am not going to be able to review this tonight or tomorrow. I'm sorry. I do hope my comment above is helpful at least.

@rhatdan rhatdan force-pushed the options branch 3 times, most recently from 3b38fea to fe36ebf Compare October 16, 2020 11:40
@rhatdan
Copy link
Member Author

rhatdan commented Oct 20, 2020

@edsantiago I think I have removed all issues with Flags, now your test script is blowing up. Could you take a look at this PR versus your test script?

@edsantiago
Copy link
Member

Patch:

diff --git a/cmd/podman/containers/list.go b/cmd/podman/containers/list.go
index daf03a51b..78a15559f 100644
--- a/cmd/podman/containers/list.go
+++ b/cmd/podman/containers/list.go
@@ -10,7 +10,7 @@ import (
 var (
        // podman container _list_
        listCmd = &cobra.Command{
-               Use:     "list",
+               Use:     "list [options]",
                Aliases: []string{"ls"},
                Args:    validate.NoArgs,
                Short:   "List containers",

That doesn't fix everything, though. ./bin/podman --help is showing Flags, not Options. I could track that down but it's probably much faster for you to do so.

@edsantiago
Copy link
Member

Next patch (assumes that you fix the Flags: error in podman --help; if you can't fix that, lmk, it's a simple tweak)

diff --git a/hack/xref-helpmsgs-manpages b/hack/xref-helpmsgs-manpages
index 7b617eed7..416d65182 100755
--- a/hack/xref-helpmsgs-manpages
+++ b/hack/xref-helpmsgs-manpages
@@ -228,14 +228,14 @@ sub podman_help {
         #    Usage: ...
         #    Available Commands:
         #       ....
-        #    Flags:
+        #    Options:
         #       ....
         #
         # Start by identifying the section we're in...
         if ($line =~ /^Available\s+(Commands):/) {
             $section = lc $1;
         }
-        elsif ($line =~ /^(Flags):/) {
+        elsif ($line =~ /^(Options):/) {
             $section = lc $1;
         }

@@ -248,7 +248,7 @@ sub podman_help {
                     unless $subcommand eq 'help';       # 'help' not in man
             }
         }
-        elsif ($section eq 'flags') {
+        elsif ($section eq 'options') {
             # Handle '--foo' or '-f, --foo'
             if ($line =~ /^\s{1,10}(--\S+)\s/) {
                 print "> podman @_ $1\n"                        if $debug;
@@ -320,7 +320,7 @@ sub podman_man {
             }
         }

-        # Flags should always be of the form '**-f**' or '**--flag**',
+        # Options should always be of the form '**-f**' or '**--flag**',
         # possibly separated by comma-space.
         elsif ($section eq 'flags') {
             # e.g. 'podman run --ip6', documented in man page, but nonexistent

@edsantiago
Copy link
Member

Here's one possible fix for setting Flags: -> Options: in podman --help

diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index eed3968e5..d23230763 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -81,6 +81,7 @@ func init() {
        )

        rootFlags(rootCmd, registry.PodmanConfig())
+       rootCmd.SetUsageTemplate(usageTemplate)
 }

 func Execute() {

Note that you do not want to set helpTemplate here: it will add an undesired Description heading.

@edsantiago
Copy link
Member

try this

diff --git a/docs/remote-docs.sh b/docs/remote-docs.sh
index a9fda4696..67c731e75 100755
--- a/docs/remote-docs.sh
+++ b/docs/remote-docs.sh
@@ -78,7 +78,7 @@ function html_fn() {
 # the command name but not its description.
 function podman_commands() {
     $PODMAN help "$@" |\
-        awk '/^Available Commands:/{ok=1;next}/^Flags:/{ok=0}ok { print $1 }' |\
+        awk '/^Available Commands:/{ok=1;next}/^Options:/{ok=0}ok { print $1 }' |\
         grep .
 }

@edsantiago
Copy link
Member

WARNING: podman: man page shows '[*options*]', help does not show [options]
WARNING: podman container exists: man page shows '[*options*]', help does not show [options]

The second is easy, just an oversight:

diff --git a/cmd/podman/containers/exists.go b/cmd/podman/containers/exists.go
index 1d79b684d..70b8af159 100644
--- a/cmd/podman/containers/exists.go
+++ b/cmd/podman/containers/exists.go
@@ -12,7 +12,7 @@ var (
        containerExistsDescription = `If the named container exists in local storage, podman container exists exits with 0, otherwise the exit code will be 1.`

        existsCommand = &cobra.Command{
-               Use:   "exists [flags] CONTAINER",
+               Use:   "exists [options] CONTAINER",
                Short: "Check if a container exists in local storage",
                Long:  containerExistsDescription,
                Example: `podman container exists --external containerID

The first is harder. Here is a side-by-side of old vs new:

$ /usr/bin/podman --help                  | $ ./bin/podman --help
Manage pods, containers and images        | Manage pods, containers and images
                                          |
Usage:                                    | Usage:
  podman [flags]                          | podman [command]
  podman [command]                        |

IOW, the podman [flags] string is gone.

Best case would be to find a way to make that line podman [options] command, since command is not optional. Is there a way to do that?

@edsantiago
Copy link
Member

This seems to have the desired (by me) effect:

diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index d23230763..54c168bd2 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -38,7 +38,7 @@ Description:
 // command should not use this.
 const usageTemplate = `Usage:{{if (and .Runnable (not .HasAvailableSubCommands))}}
   {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
-  {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
+  {{.CommandPath}}{{if .HasAvailableLocalFlags}} [options]{{end}} command{{end}}{{if gt (len .Aliases) 0}}

 Aliases:
   {{.NameAndAliases}}{{end}}{{if .HasExample}}
diff --git a/test/system/015-help.bats b/test/system/015-help.bats
index 22db8be8a..d6a8a80c9 100644
--- a/test/system/015-help.bats
+++ b/test/system/015-help.bats
@@ -3,7 +3,7 @@
 # Tests based on 'podman help'
 #
 # Find all commands listed by 'podman --help'. Run each one, make sure it
-# provides its own --help output. If the usage message ends in '[command]',
+# provides its own --help output. If the usage message ends in 'command',
 # treat it as a subcommand, and recurse into its own list of sub-subcommands.
 #
 # Any usage message that ends in '[options]' is interpreted as a command
@@ -45,8 +45,8 @@ function check_help() {
         # has no ' [options]'
         is "$usage " "  $command_string .*" "Usage string matches command"

-        # If usage ends in '[command]', recurse into subcommands
-        if expr "$usage" : '.*\[command\]$' >/dev/null; then
+        # If usage ends in 'command', recurse into subcommands
+        if expr "$usage" : '.*command$' >/dev/null; then
             found[subcommands]=1
             check_help "$@" $cmd
             continue

I don't know if others will find that 'command' (no brackets) desirable; nor do I know what other side effects it might have.

Also, I think you lost one of the changes I specified above. You'll need to apply this to get the man-page xref to pass:

diff --git a/hack/xref-helpmsgs-manpages b/hack/xref-helpmsgs-manpages
index a7063259f..416d65182 100755
--- a/hack/xref-helpmsgs-manpages
+++ b/hack/xref-helpmsgs-manpages
@@ -248,7 +248,7 @@ sub podman_help {
                     unless $subcommand eq 'help';       # 'help' not in man
             }
         }
-        elsif ($section eq 'flags') {
+        elsif ($section eq 'options') {
             # Handle '--foo' or '-f, --foo'
             if ($line =~ /^\s{1,10}(--\S+)\s/) {
                 print "> podman @_ $1\n"                        if $debug;

@edsantiago
Copy link
Member

I think you missed this one #8034 (comment)

@edsantiago
Copy link
Member

While you're at it would you mind

diff --git a/completions/zsh/_podman b/completions/zsh/_podman
index 067eebbbb..80dc5125d 100644
--- a/completions/zsh/_podman
+++ b/completions/zsh/_podman
@@ -206,7 +206,7 @@ _set_up_podman_args() {

     typeset -ga _podman_args=()
     # E.g. 'podman exec [flags] CONTAINER [...' -> 'CONTAINER [....'
-    local usage_rhs=$(expr "$_podman_usage" : ".*\[flags\] \+\(.*\)")
+    local usage_rhs=$(expr "$_podman_usage" : ".*\[options\] \+\(.*\)")

     # e.g. podman pod ps which takes no further args
     if [ -z "$usage_rhs" ]; then

Want to have man pages match commands, since we have lots of printed
man pages with using Options, we will change the command line to use
Options in --help.

Signed-off-by: Daniel J Walsh <[email protected]>
@edsantiago
Copy link
Member

Error was:

Trying to pull quay.io/libpod/fedora-minimal:latest...
[...]
Timed out after 90.000s.

Treating as a flake. Restarted.

@edsantiago
Copy link
Member

/lgtm
/hold

@containers/podman-maintainers PTAL, let's get this in before some breaking change merges and causes conflicts

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 21, 2020
@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 21, 2020
@mheon
Copy link
Member

mheon commented Oct 21, 2020

LGTM
/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 21, 2020
@openshift-merge-robot openshift-merge-robot merged commit a1b942f into containers:master Oct 21, 2020
edsantiago added a commit to edsantiago/libpod that referenced this pull request Nov 11, 2020
Somewhere in the CIv2 migration we lost the man page vs --help
cross-checker. Add it back, by adding it into the man-page-check
Makefile target; this is part of 'make validate', which is run
in CI even on CI:DOCS PRs.

As happens when CI doesn't run, things broke. Man pages got out
of sync with --help. This PR:

 1) Fixes hack/xref-helpmsgs-manpages to deal with the new
    "Options" (instead of "Flags") form of podman help. containers#8034
    did part of that, but one of my review comments was
    accidentally left out.

 2) Fixes hack/xref-helpmsgs-manpages to deal with the new
    option syntax in man pages, post- containers#8292, in which each
    option is preceded by four hashes so as to make them
    HTML <h4> elements with named anchors.

 3) Fixes man pages that containers#8292 accidentally missed.

 4) Adds man page entries for two flags that got added
    to podman but not documented (pod create --network-alias,
    play kube --log-driver)

Fixes: containers#8296

Signed-off-by: Ed Santiago <[email protected]>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants