Skip to content

Fix help message flags on docker stack commands and sub-commands#1251

Merged
thaJeztah merged 1 commit into
docker:masterfrom
silvin-lubecki:fix-stack-help-command
Aug 2, 2018
Merged

Fix help message flags on docker stack commands and sub-commands#1251
thaJeztah merged 1 commit into
docker:masterfrom
silvin-lubecki:fix-stack-help-command

Conversation

@silvin-lubecki
Copy link
Copy Markdown
Contributor

- What I did
Fix issue #1243
Add an e2e test as regression test

- How I did it
PersistentPreRunE needs to be called within the help function to initialize all the flags (notably the orchestrator flag)

- How to verify it

$ docker stack deploy --help --orchestrator=kubernetes

Usage:	docker stack deploy [OPTIONS] STACK

Deploy a new stack or update an existing stack

Aliases:
  deploy, up

Options:
  -c, --compose-file strings   Path to a Compose file, or "-" to read from stdin
      --kubeconfig string      Kubernetes config file
      --namespace string       Kubernetes namespace to use
      --orchestrator string    Orchestrator to use (swarm|kubernetes|all)

$ docker stack deploy --help --orchestrator=swarm

Usage:	docker stack deploy [OPTIONS] STACK

Deploy a new stack or update an existing stack

Aliases:
  deploy, up

Options:
      --bundle-file string     Path to a Distributed Application Bundle file
  -c, --compose-file strings   Path to a Compose file, or "-" to read from stdin
      --orchestrator string    Orchestrator to use (swarm|kubernetes|all)
      --prune                  Prune services that are no longer referenced
      --resolve-image string   Query the registry to resolve image digest and supported platforms ("always"|"changed"|"never") (default "always")
      --with-registry-auth     Send registry authentication details to Swarm agents

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)
image

Lots of kudos for @albers !!

PersistentPreRunE needs to be called within the help function to initialize all the flags (notably the orchestrator flag)
Add an e2e test as regression test

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #1251 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master    #1251      +/-   ##
==========================================
- Coverage   54.23%   54.21%   -0.02%     
==========================================
  Files         268      268              
  Lines       17809    17814       +5     
==========================================
  Hits         9658     9658              
- Misses       7543     7548       +5     
  Partials      608      608

Comment thread e2e/stack/help_test.go
func testStackDeployHelp(t *testing.T, orchestrator string) {
result := icmd.RunCommand("docker", "stack", "deploy", "--orchestrator", orchestrator, "--help")
result.Assert(t, icmd.Success)
golden.Assert(t, result.Stdout(), fmt.Sprintf("stack-deploy-help-%s.golden", orchestrator))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this the commonly used way to verify command outputs in this project? This will break every time an option or help message is added/modified, this producing unnecessary maintenance work.

Alternatively, we could check for the presence of specific flags via substring checks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@albers I think it's safe to "break every time" on that command as we don't often change those, and if we do well, the test is easily fixable (go test -update or sthg like that). I do agree it's not ideal though, but 😅

Copy link
Copy Markdown
Collaborator

@albers albers left a comment

Choose a reason for hiding this comment

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

Works perfectly, thanks a lot.

@albers
Copy link
Copy Markdown
Collaborator

albers commented Aug 1, 2018

There is also a problem in docker version: --kubeconfig is annotated as kubernetes but visible for the swarm orchestrator.

# DOCKER_STACK_ORCHESTRATOR=swarm docker version --help | grep kubeconfig
      --kubeconfig string   Kubernetes config file
# DOCKER_STACK_ORCHESTRATOR=kubernetes docker version --help | grep kubeconfig
      --kubeconfig string   Kubernetes config file
# docker --version
Docker version 18.09.0-dev, build 21cce52b

Copy link
Copy Markdown
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🦁

Comment thread e2e/stack/help_test.go
func testStackDeployHelp(t *testing.T, orchestrator string) {
result := icmd.RunCommand("docker", "stack", "deploy", "--orchestrator", orchestrator, "--help")
result.Assert(t, icmd.Success)
golden.Assert(t, result.Stdout(), fmt.Sprintf("stack-deploy-help-%s.golden", orchestrator))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@albers I think it's safe to "break every time" on that command as we don't often change those, and if we do well, the test is easily fixable (go test -update or sthg like that). I do agree it's not ideal though, but 😅

@silvin-lubecki
Copy link
Copy Markdown
Contributor Author

@albers I'll fix the docker version flags in a follow-up.

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

was wondering if this should be a unit-test, but looks like that requires more rigging if we need the full output

@thaJeztah thaJeztah merged commit 4fbb009 into docker:master Aug 2, 2018
@GordonTheTurtle GordonTheTurtle added this to the 18.09.0 milestone Aug 2, 2018
@silvin-lubecki
Copy link
Copy Markdown
Contributor Author

Well the problem is that the root docker command does a lot of stuffs with the help command (formatting included), so testing at the stack command level won't really help testing the final feature.

@albers
Copy link
Copy Markdown
Collaborator

albers commented Aug 3, 2018

I'll fix the docker version flags in a follow-up.

@silvin-lubecki I created #1265 as a reminder.

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.

docker stack deploy help is missing orchestration specific flags

6 participants