mirror of https://github.com/docker/cli.git
formatter: minor refactor to reduce needless conversions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
8fc038afe7
commit
b951b5b8c9
|
@ -103,9 +103,9 @@ func (cs *Stats) GetStatistics() StatsEntry {
|
||||||
func NewStatsFormat(source, osType string) formatter.Format {
|
func NewStatsFormat(source, osType string) formatter.Format {
|
||||||
if source == formatter.TableFormatKey {
|
if source == formatter.TableFormatKey {
|
||||||
if osType == winOSType {
|
if osType == winOSType {
|
||||||
return formatter.Format(winDefaultStatsTableFormat)
|
return winDefaultStatsTableFormat
|
||||||
}
|
}
|
||||||
return formatter.Format(defaultStatsTableFormat)
|
return defaultStatsTableFormat
|
||||||
}
|
}
|
||||||
return formatter.Format(source)
|
return formatter.Format(source)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,10 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// KubernetesStackTableFormat is the default Kubernetes stack format
|
// KubernetesStackTableFormat is the default Kubernetes stack format
|
||||||
KubernetesStackTableFormat = "table {{.Name}}\t{{.Services}}\t{{.Orchestrator}}\t{{.Namespace}}"
|
KubernetesStackTableFormat formatter.Format = "table {{.Name}}\t{{.Services}}\t{{.Orchestrator}}\t{{.Namespace}}"
|
||||||
|
|
||||||
// SwarmStackTableFormat is the default Swarm stack format
|
// SwarmStackTableFormat is the default Swarm stack format
|
||||||
SwarmStackTableFormat = "table {{.Name}}\t{{.Services}}\t{{.Orchestrator}}"
|
SwarmStackTableFormat formatter.Format = "table {{.Name}}\t{{.Services}}\t{{.Orchestrator}}"
|
||||||
|
|
||||||
stackServicesHeader = "SERVICES"
|
stackServicesHeader = "SERVICES"
|
||||||
stackOrchestrastorHeader = "ORCHESTRATOR"
|
stackOrchestrastorHeader = "ORCHESTRATOR"
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestStackContextWrite(t *testing.T) {
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{
|
{
|
||||||
formatter.Context{Format: formatter.Format(SwarmStackTableFormat)},
|
formatter.Context{Format: SwarmStackTableFormat},
|
||||||
`NAME SERVICES ORCHESTRATOR
|
`NAME SERVICES ORCHESTRATOR
|
||||||
baz 2 orchestrator1
|
baz 2 orchestrator1
|
||||||
bar 1 orchestrator2
|
bar 1 orchestrator2
|
||||||
|
@ -35,7 +35,7 @@ bar 1 orchestrator2
|
||||||
},
|
},
|
||||||
// Kubernetes table format adds Namespace column
|
// Kubernetes table format adds Namespace column
|
||||||
{
|
{
|
||||||
formatter.Context{Format: formatter.Format(KubernetesStackTableFormat)},
|
formatter.Context{Format: KubernetesStackTableFormat},
|
||||||
`NAME SERVICES ORCHESTRATOR NAMESPACE
|
`NAME SERVICES ORCHESTRATOR NAMESPACE
|
||||||
baz 2 orchestrator1 namespace1
|
baz 2 orchestrator1 namespace1
|
||||||
bar 1 orchestrator2 namespace2
|
bar 1 orchestrator2 namespace2
|
||||||
|
|
|
@ -60,7 +60,7 @@ func RunList(cmd *cobra.Command, dockerCli command.Cli, opts options.List, orche
|
||||||
}
|
}
|
||||||
|
|
||||||
func format(dockerCli command.Cli, opts options.List, orchestrator command.Orchestrator, stacks []*formatter.Stack) error {
|
func format(dockerCli command.Cli, opts options.List, orchestrator command.Orchestrator, stacks []*formatter.Stack) error {
|
||||||
format := opts.Format
|
format := formatter.Format(opts.Format)
|
||||||
if format == "" || format == formatter.TableFormatKey {
|
if format == "" || format == formatter.TableFormatKey {
|
||||||
format = formatter.SwarmStackTableFormat
|
format = formatter.SwarmStackTableFormat
|
||||||
if orchestrator.HasKubernetes() {
|
if orchestrator.HasKubernetes() {
|
||||||
|
@ -69,7 +69,7 @@ func format(dockerCli command.Cli, opts options.List, orchestrator command.Orche
|
||||||
}
|
}
|
||||||
stackCtx := formatter.Context{
|
stackCtx := formatter.Context{
|
||||||
Output: dockerCli.Out(),
|
Output: dockerCli.Out(),
|
||||||
Format: formatter.Format(format),
|
Format: format,
|
||||||
}
|
}
|
||||||
sort.Slice(stacks, func(i, j int) bool {
|
sort.Slice(stacks, func(i, j int) bool {
|
||||||
return sortorder.NaturalLess(stacks[i].Name, stacks[j].Name) ||
|
return sortorder.NaturalLess(stacks[i].Name, stacks[j].Name) ||
|
||||||
|
|
Loading…
Reference in New Issue