mirror of https://github.com/docker/cli.git
Remove duplication in task formatting.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
fb6deb1077
commit
0030bfea9f
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
|
||||||
"github.com/docker/cli/cli/command/idresolver"
|
"github.com/docker/cli/cli/command/idresolver"
|
||||||
"github.com/docker/cli/cli/command/task"
|
"github.com/docker/cli/cli/command/task"
|
||||||
"github.com/docker/cli/opts"
|
"github.com/docker/cli/opts"
|
||||||
|
@ -88,11 +87,7 @@ func runPs(dockerCli command.Cli, options psOptions) error {
|
||||||
|
|
||||||
format := options.format
|
format := options.format
|
||||||
if len(format) == 0 {
|
if len(format) == 0 {
|
||||||
if dockerCli.ConfigFile() != nil && len(dockerCli.ConfigFile().TasksFormat) > 0 && !options.quiet {
|
format = task.DefaultFormat(dockerCli.ConfigFile(), options.quiet)
|
||||||
format = dockerCli.ConfigFile().TasksFormat
|
|
||||||
} else {
|
|
||||||
format = formatter.TableFormatKey
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) == 0 || len(tasks) != 0 {
|
if len(errs) == 0 || len(tasks) != 0 {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
|
||||||
"github.com/docker/cli/cli/command/idresolver"
|
"github.com/docker/cli/cli/command/idresolver"
|
||||||
"github.com/docker/cli/cli/command/node"
|
"github.com/docker/cli/cli/command/node"
|
||||||
"github.com/docker/cli/cli/command/task"
|
"github.com/docker/cli/cli/command/task"
|
||||||
|
@ -65,11 +64,7 @@ func runPS(dockerCli command.Cli, options psOptions) error {
|
||||||
|
|
||||||
format := options.format
|
format := options.format
|
||||||
if len(format) == 0 {
|
if len(format) == 0 {
|
||||||
if len(dockerCli.ConfigFile().TasksFormat) > 0 && !options.quiet {
|
format = task.DefaultFormat(dockerCli.ConfigFile(), options.quiet)
|
||||||
format = dockerCli.ConfigFile().TasksFormat
|
|
||||||
} else {
|
|
||||||
format = formatter.TableFormatKey
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {
|
if err := task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
|
||||||
"github.com/docker/cli/cli/command/idresolver"
|
"github.com/docker/cli/cli/command/idresolver"
|
||||||
"github.com/docker/cli/cli/command/task"
|
"github.com/docker/cli/cli/command/task"
|
||||||
"github.com/docker/cli/opts"
|
"github.com/docker/cli/opts"
|
||||||
|
@ -64,11 +63,7 @@ func runPS(dockerCli command.Cli, options psOptions) error {
|
||||||
|
|
||||||
format := options.format
|
format := options.format
|
||||||
if len(format) == 0 {
|
if len(format) == 0 {
|
||||||
if len(dockerCli.ConfigFile().TasksFormat) > 0 && !options.quiet {
|
format = task.DefaultFormat(dockerCli.ConfigFile(), options.quiet)
|
||||||
format = dockerCli.ConfigFile().TasksFormat
|
|
||||||
} else {
|
|
||||||
format = formatter.TableFormatKey
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format)
|
return task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format)
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/cli/cli/command/idresolver"
|
"github.com/docker/cli/cli/command/idresolver"
|
||||||
|
"github.com/docker/cli/cli/config/configfile"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tasksBySlot []swarm.Task
|
type tasksBySlot []swarm.Task
|
||||||
|
@ -82,3 +82,12 @@ func Print(ctx context.Context, dockerCli command.Cli, tasks []swarm.Task, resol
|
||||||
|
|
||||||
return formatter.TaskWrite(tasksCtx, tasks, names, nodes)
|
return formatter.TaskWrite(tasksCtx, tasks, names, nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultFormat returns the default format from the config file, or table
|
||||||
|
// format if nothing is set in the config.
|
||||||
|
func DefaultFormat(configFile *configfile.ConfigFile, quiet bool) string {
|
||||||
|
if len(configFile.TasksFormat) > 0 && !quiet {
|
||||||
|
return configFile.TasksFormat
|
||||||
|
}
|
||||||
|
return formatter.TableFormatKey
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue