Add --no-trunc to service/node/stack ps output

Signed-off-by: Josh Horwitz <horwitzja@gmail.com>
This commit is contained in:
Josh Horwitz 2016-08-02 12:25:14 -04:00
parent eb28dde01f
commit 204c4d39d3
8 changed files with 17 additions and 7 deletions

View File

@ -15,6 +15,7 @@ import (
type psOptions struct { type psOptions struct {
nodeID string nodeID string
noResolve bool noResolve bool
noTrunc bool
filter opts.FilterOpt filter opts.FilterOpt
} }
@ -31,6 +32,7 @@ func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
@ -59,5 +61,5 @@ func runPS(dockerCli *client.DockerCli, opts psOptions) error {
return err return err
} }
return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve)) return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), opts.noTrunc)
} }

View File

@ -16,6 +16,7 @@ import (
type psOptions struct { type psOptions struct {
serviceID string serviceID string
noResolve bool noResolve bool
noTrunc bool
filter opts.FilterOpt filter opts.FilterOpt
} }
@ -32,6 +33,7 @@ func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
@ -66,5 +68,5 @@ func runPS(dockerCli *client.DockerCli, opts psOptions) error {
return err return err
} }
return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve)) return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), opts.noTrunc)
} }

View File

@ -20,6 +20,7 @@ import (
type psOptions struct { type psOptions struct {
all bool all bool
filter opts.FilterOpt filter opts.FilterOpt
noTrunc bool
namespace string namespace string
noResolve bool noResolve bool
} }
@ -38,6 +39,7 @@ func newPSCommand(dockerCli *client.DockerCli) *cobra.Command {
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.all, "all", "a", false, "Display all tasks") flags.BoolVarP(&opts.all, "all", "a", false, "Display all tasks")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
@ -66,5 +68,5 @@ func runPS(dockerCli *client.DockerCli, opts psOptions) error {
return nil return nil
} }
return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve)) return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), opts.noTrunc)
} }

View File

@ -41,7 +41,7 @@ func (t tasksBySlot) Less(i, j int) bool {
} }
// Print task information in a table format // Print task information in a table format
func Print(dockerCli *client.DockerCli, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver) error { func Print(dockerCli *client.DockerCli, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error {
sort.Stable(tasksBySlot(tasks)) sort.Stable(tasksBySlot(tasks))
writer := tabwriter.NewWriter(dockerCli.Out(), 0, 4, 2, ' ', 0) writer := tabwriter.NewWriter(dockerCli.Out(), 0, 4, 2, ' ', 0)
@ -75,7 +75,7 @@ func Print(dockerCli *client.DockerCli, ctx context.Context, tasks []swarm.Task,
// Trim and quote the error message. // Trim and quote the error message.
taskErr := task.Status.Err taskErr := task.Status.Err
if len(taskErr) > maxErrLength { if !noTrunc && len(taskErr) > maxErrLength {
taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1]) taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1])
} }
if len(taskErr) > 0 { if len(taskErr) > 0 {

View File

@ -1704,7 +1704,7 @@ _docker_service_ps() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve" -- "$cur" ) ) COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
;; ;;
*) *)
local counter=$(__docker_pos_first_nonflag '--filter|-f') local counter=$(__docker_pos_first_nonflag '--filter|-f')
@ -2076,7 +2076,7 @@ _docker_node_ps() {
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve" -- "$cur" ) ) COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
;; ;;
*) *)
local counter=$(__docker_pos_first_nonflag '--filter|-f') local counter=$(__docker_pos_first_nonflag '--filter|-f')

View File

@ -841,6 +841,7 @@ __docker_node_subcommand() {
"($help -a --all)"{-a,--all}"[Display all instances]" \ "($help -a --all)"{-a,--all}"[Display all instances]" \
"($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
"($help)--no-resolve[Do not map IDs to Names]" \ "($help)--no-resolve[Do not map IDs to Names]" \
"($help)--no-trunc[Do not truncate output]" \
"($help -)1:node:__docker_complete_nodes" && ret=0 "($help -)1:node:__docker_complete_nodes" && ret=0
case $state in case $state in
(filter-options) (filter-options)
@ -1156,6 +1157,7 @@ __docker_service_subcommand() {
"($help -a --all)"{-a,--all}"[Display all tasks]" \ "($help -a --all)"{-a,--all}"[Display all tasks]" \
"($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
"($help)--no-resolve[Do not map IDs to Names]" \ "($help)--no-resolve[Do not map IDs to Names]" \
"($help)--no-trunc[Do not truncate output]" \
"($help -)1:service:__docker_complete_services" && ret=0 "($help -)1:service:__docker_complete_services" && ret=0
case $state in case $state in
(filter-options) (filter-options)

View File

@ -21,6 +21,7 @@ Options:
-f, --filter value Filter output based on conditions provided -f, --filter value Filter output based on conditions provided
--help Print usage --help Print usage
--no-resolve Do not map IDs to Names --no-resolve Do not map IDs to Names
--no-trunc Do not truncate output
``` ```
Lists all the tasks on a Node that Docker knows about. You can filter using the `-f` or `--filter` flag. Refer to the [filtering](#filtering) section for more information about available filter options. Lists all the tasks on a Node that Docker knows about. You can filter using the `-f` or `--filter` flag. Refer to the [filtering](#filtering) section for more information about available filter options.

View File

@ -21,6 +21,7 @@ Options:
-f, --filter value Filter output based on conditions provided -f, --filter value Filter output based on conditions provided
--help Print usage --help Print usage
--no-resolve Do not map IDs to Names --no-resolve Do not map IDs to Names
--no-trunc Do not truncate output
``` ```
Lists the tasks that are running as part of the specified service. This command Lists the tasks that are running as part of the specified service. This command