-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add --format
to docker service ls
#28199
Conversation
SGTM, can you add tests? |
Design SGTM 👼 |
cli/command/service/list.go
Outdated
@@ -40,6 +36,8 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command { | |||
|
|||
flags := cmd.Flags() | |||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") | |||
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should consider introducing ShortID
and/or TruncID
placeholders. The TruncID
placeholder has the behavior of what ID
has now (so, truncated by default, but show full ID if --trunc
is added. That way people can define a template where the output always has the full-id, or has an ID that can be truncated or full.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thaJeztah does that mean we will leave ID
alone regardless of --no-trunc=false/true
, and only trunc TruncID
based on --no-trunc=true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yongtang perhaps, yes. My initial thought was "do we need a --no-trunc
flag? That's when I started thinking if we perhaps need other options for the format.
It's just a thought though, so perhaps @vdemeester or @dnephin has some thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same though as @thaJeztah, I don't really like --no-trunc
flag, especially since format uses go template. We could provide a function that shorten "or not" the ID : --format="{{ .ID | shorten }}"
or something like that.
1e001a5
to
c5ba328
Compare
@AkihiroSuda Added a test for the PR. |
Design LGTM, let's keep #28199 (comment) for another discussion |
ping @yongtang, needs a rebase 👼 |
c5ba328
to
9113044
Compare
Thanks @vdemeester. The PR has been rebased. |
|
9113044
to
c411a9b
Compare
Thanks @AkihiroSuda. The PR has been updated with golint issue addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments 👼
I do agree with @thaJeztah on the --no-trunc
flags (on other commands as well but 😅)
cli/command/service/list.go
Outdated
@@ -40,6 +36,8 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command { | |||
|
|||
flags := cmd.Flags() | |||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") | |||
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same though as @thaJeztah, I don't really like --no-trunc
flag, especially since format uses go template. We could provide a function that shorten "or not" the ID : --format="{{ .ID | shorten }}"
or something like that.
cli/command/service/list.go
Outdated
} | ||
mode[service.ID] = "global" | ||
replicas[service.ID] = fmt.Sprintf("%d/%d", running[service.ID], tasksNoShutdown[service.ID]) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else
is empty right ? should go 👼
cli/command/service/list.go
Outdated
// Besides this, command `docker stack services xxx` will call this, too. | ||
func PrintNotQuiet(out io.Writer, services []swarm.Service, nodes []swarm.Node, tasks []swarm.Task) { | ||
// GetServicesStatus returns a map of mode and replicas | ||
func GetServicesStatus(services []swarm.Service, nodes []swarm.Node, tasks []swarm.Task) (map[string]string, map[string]string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should/Could this return a map of struct instead, with mode and replica in the struct, instead of two maps ? 👼
45533cd
to
09edc91
Compare
@vdemeester @thaJeztah Thanks for the review. The PR has been updated and now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🐸
@@ -1630,3 +1630,33 @@ func (s *DockerSwarmSuite) TestSwarmInitWithDrain(c *check.C) { | |||
c.Assert(err, checker.IsNil) | |||
c.Assert(out, checker.Contains, "Drain") | |||
} | |||
|
|||
func (s *DockerSwarmSuite) TestSwarmServiceListFormat(c *check.C) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder this test can be moved to UT, but it can be another PR in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍
`.ID` | Service ID | ||
`.Name` | Service name | ||
`.Mode` | Service mode (replicated, global) | ||
`.Replicas` | Service replicas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder we should have two separate placeholders e.g. RunningReplicas
and AllReplicas
.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AkihiroSuda I feel like that means we introduce new concepts that does not necessary match the existing Table header. Should we change the table header to RUNNING/ALL REPLICAS
? Or maybe we could leave it alone for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is ok to introduce all .Replicas
, .RunningReplicas
, and .AllReplicas
.
But it is ok to leave it alone for now.
09edc91
to
6bf3b16
Compare
6bf3b16
to
e60ec5d
Compare
Thanks @thaJeztah. The PR has been updated. Also created another PR #30484 for Also in this PR I didn't add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🐯
Moving to docs-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yongtang Could you update docs/reference/commandline/cli.md
to add an example for ServicesFormat
?
Thanks @vdemeester. The docs has been updated in the PR. Please take a look and let me know if there are any issues. |
e60ec5d
to
90e4711
Compare
This fix tries to improve the display of `docker service ls` and adds `--format` flag to `docker service ls`. In addition to `--format` flag, several other improvement: 1. Updates `docker stacks service`. 2. Adds `servicesFormat` to config file. Related docs has been updated. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
90e4711
to
000f040
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs LGTM 🐸
/cc @thaJeztah for docs revisit
Add `--format` to `docker service ls`
- What I did
This fix tries to improve the display of
docker service ls
and adds--format
flag todocker service ls
.In addition to
--format
flag, several other improvement:--no-trunc
todocker service ls
docker stacks service
.servicesFormat
to config file.Related docs has been updated.
cc @thaJeztah @vdemeester @dnephin
- A picture of a cute animal (not mandatory but encouraged)
Signed-off-by: Yong Tang yong.tang.github@outlook.com