Skip to content

Add syntax and examples to the description text of some complex options#3417

Open
gibson042 wants to merge 6 commits into
docker:masterfrom
gibson042:2022-01-improve-cli-option-documentation
Open

Add syntax and examples to the description text of some complex options#3417
gibson042 wants to merge 6 commits into
docker:masterfrom
gibson042:2022-01-improve-cli-option-documentation

Conversation

@gibson042
Copy link
Copy Markdown

@gibson042 gibson042 commented Feb 1, 2022

- What I did

- How I did it
Updated flags description arguments in cli/command/ files.

- How to verify it
Build the docker executable and invoke it with help run or help create.

- Description for the changelog
Add syntax and examples to the description text of some complex options.

- A picture of a cute animal (not mandatory but encouraged)
https://twitter.com/EveryBat/status/1229018840308125696
a bat covered in yellow pollen

@gibson042 gibson042 requested a review from thaJeztah as a code owner February 1, 2022 19:06
@@ -14,122 +14,113 @@ Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
Create a new container

Options:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These changes are best viewed while ignoring whitespace. There are some actual changes, but only because docs/reference/commandline/ apparently contains stale content.

"type=volume,target=/mnt/persistent" or
"type=bind,ro,src=/var/run/docker.sock,dst=/run/host-docker.sock")
--name string Assign a name to the container
--network network Connect a container to a network
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Should the list of special --network values be documented by the actual description in cli/command/container/opts.go?

--shm-size bytes Size of /dev/shm
The format is `<number><unit>`. `number` must be greater than `0`.
Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes),
or `g` (gigabytes). If you omit the unit, the system uses bytes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is this ability to specify --shm-size units accurate, and if so should it be documented by the actual description in cli/command/container/opts.go?

-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
--userns string User namespace to use
'host': Use the Docker host user namespace
'': Use the Docker daemon user namespace specified by `--userns-remap` option.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Should the list of special --userns values be documented by the actual description in cli/command/container/opts.go?

--userns string User namespace to use
--uts string UTS namespace to use
-v, --volume list Bind mount a volume (format: [<volume name|absolute
host path>:]<absolute container path>[:<options>])
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Should the description of --volume in cli/command/container/opts.go include the list of options?

@gibson042
Copy link
Copy Markdown
Author

I'm also not clear on how (if at all) contrib/completion/ files should be updated.

--entrypoint string Overwrite the default ENTRYPOINT of the image
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
--expose list Expose a port or a range of ports
Copy link
Copy Markdown
Author

@gibson042 gibson042 Feb 1, 2022

Choose a reason for hiding this comment

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

"range of ports" seems sufficiently special to merit more text, perhaps something like this?

      --expose list                    Expose a port or a range of ports (e.g., "80,443,2379-2380")

Signed-off-by: Richard Gibson <richard.gibson@gmail.com>
```sh
for cmd in create run; do
  doc="docs/reference/commandline/$cmd.md"
  tmp="$(mktemp)"
  awk -v cmd="$cmd" '
    # Replace the contents of the first markdown block
    # with output from docker help (omitting leading blank lines).
    /^```markdown/ && !replaced {
      # Print the block start.
      print;

      # Insert `docker help` output.
      while(("./build/docker help " cmd | getline)>0) {
        if(NF>0) trimmed=1;
        if(trimmed) print;
      }

      # Advance to the block end.
      while(getline>0 && $0!="```");

      replaced++;
    }

    { print }
  ' "$doc" >"$tmp" && \
  mv "$tmp" "$doc"
done
```

Signed-off-by: Richard Gibson <richard.gibson@gmail.com>
Signed-off-by: Richard Gibson <richard.gibson@gmail.com>
Signed-off-by: Richard Gibson <richard.gibson@gmail.com>
```sh
for cmd in build create run update; do
  doc="docs/reference/commandline/$cmd.md"
  tmp="$(mktemp)"
  awk -v cmd="$cmd" '
    # Replace the contents of the first markdown block
    # with output from docker help (omitting leading blank lines).
    /^```markdown/ && !replaced {
      # Print the block start.
      print;

      # Insert `docker help` output.
      while(("./build/docker help " cmd | getline)>0) {
        if(NF>0) trimmed=1;
        if(trimmed) print;
      }

      # Advance to the block end.
      while(getline>0 && $0!="```");

      replaced++;
    }

    { print }
  ' "$doc" >"$tmp" && \
  mv "$tmp" "$doc"
done
```

Signed-off-by: Richard Gibson <richard.gibson@gmail.com>
Signed-off-by: Richard Gibson <richard.gibson@gmail.com>
@gibson042 gibson042 force-pushed the 2022-01-improve-cli-option-documentation branch from 78648be to 3f807a4 Compare February 17, 2022 19:07
@thaJeztah thaJeztah added this to the 29.6.0 milestone May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants