Remove duplication in task formatting.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 0030bfea9f
Component: cli
This commit is contained in:
Daniel Nephin
2017-07-05 13:40:47 -04:00
parent 6d92cf3a08
commit 2af533daad
4 changed files with 14 additions and 20 deletions
+11 -2
View File
@@ -4,12 +4,12 @@ import (
"fmt"
"sort"
"golang.org/x/net/context"
"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/config/configfile"
"github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context"
)
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)
}
// 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
}