mirror of https://github.com/docker/cli.git
Merge pull request #4343 from thaJeztah/cleanup_sprintf
replace some basic uses of fmt.Sprintf(), and minor refactor
This commit is contained in:
commit
085d5c2816
|
@ -103,7 +103,7 @@ func (c *configContext) Labels() string {
|
||||||
}
|
}
|
||||||
var joinLabels []string
|
var joinLabels []string
|
||||||
for k, v := range mapLabels {
|
for k, v := range mapLabels {
|
||||||
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
|
joinLabels = append(joinLabels, k+"="+v)
|
||||||
}
|
}
|
||||||
return strings.Join(joinLabels, ",")
|
return strings.Join(joinLabels, ",")
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptio
|
||||||
if v == nil {
|
if v == nil {
|
||||||
newEnv = append(newEnv, k)
|
newEnv = append(newEnv, k)
|
||||||
} else {
|
} else {
|
||||||
newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, *v))
|
newEnv = append(newEnv, k+"="+*v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
copts.env = *opts.NewListOptsRef(&newEnv, nil)
|
copts.env = *opts.NewListOptsRef(&newEnv, nil)
|
||||||
|
|
|
@ -101,7 +101,7 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt
|
||||||
if v == nil {
|
if v == nil {
|
||||||
newEnv = append(newEnv, k)
|
newEnv = append(newEnv, k)
|
||||||
} else {
|
} else {
|
||||||
newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, *v))
|
newEnv = append(newEnv, k+"="+*v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
copts.env = *opts.NewListOptsRef(&newEnv, nil)
|
copts.env = *opts.NewListOptsRef(&newEnv, nil)
|
||||||
|
|
|
@ -247,7 +247,7 @@ func (c *ContainerContext) Labels() string {
|
||||||
|
|
||||||
var joinLabels []string
|
var joinLabels []string
|
||||||
for k, v := range c.c.Labels {
|
for k, v := range c.c.Labels {
|
||||||
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
|
joinLabels = append(joinLabels, k+"="+v)
|
||||||
}
|
}
|
||||||
return strings.Join(joinLabels, ",")
|
return strings.Join(joinLabels, ",")
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ func (c *networkContext) Labels() string {
|
||||||
|
|
||||||
var joinLabels []string
|
var joinLabels []string
|
||||||
for k, v := range c.n.Labels {
|
for k, v := range c.n.Labels {
|
||||||
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
|
joinLabels = append(joinLabels, k+"="+v)
|
||||||
}
|
}
|
||||||
return strings.Join(joinLabels, ",")
|
return strings.Join(joinLabels, ",")
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ func (c *secretContext) Labels() string {
|
||||||
}
|
}
|
||||||
var joinLabels []string
|
var joinLabels []string
|
||||||
for k, v := range mapLabels {
|
for k, v := range mapLabels {
|
||||||
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
|
joinLabels = append(joinLabels, k+"="+v)
|
||||||
}
|
}
|
||||||
return strings.Join(joinLabels, ",")
|
return strings.Join(joinLabels, ",")
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ func prettyPrintEvent(out io.Writer, event eventtypes.Message) error {
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
v := event.Actor.Attributes[k]
|
v := event.Actor.Attributes[k]
|
||||||
attrs = append(attrs, fmt.Sprintf("%s=%s", k, v))
|
attrs = append(attrs, k+"="+v)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", "))
|
fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", "))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -134,7 +133,7 @@ func Service(
|
||||||
Hosts: convertExtraHosts(service.ExtraHosts),
|
Hosts: convertExtraHosts(service.ExtraHosts),
|
||||||
DNSConfig: dnsConfig,
|
DNSConfig: dnsConfig,
|
||||||
Healthcheck: healthcheck,
|
Healthcheck: healthcheck,
|
||||||
Env: sortStrings(convertEnvironment(service.Environment)),
|
Env: convertEnvironment(service.Environment),
|
||||||
Labels: AddStackLabel(namespace, service.Labels),
|
Labels: AddStackLabel(namespace, service.Labels),
|
||||||
Dir: service.WorkingDir,
|
Dir: service.WorkingDir,
|
||||||
User: service.User,
|
User: service.User,
|
||||||
|
@ -200,11 +199,6 @@ func getPlacementPreference(preferences []composetypes.PlacementPreferences) []s
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortStrings(strs []string) []string {
|
|
||||||
sort.Strings(strs)
|
|
||||||
return strs
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertServiceNetworks(
|
func convertServiceNetworks(
|
||||||
networks map[string]*composetypes.ServiceNetworkConfig,
|
networks map[string]*composetypes.ServiceNetworkConfig,
|
||||||
networkConfigs networkMap,
|
networkConfigs networkMap,
|
||||||
|
@ -597,6 +591,8 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convertEnvironment converts key/value mappings to a slice, and sorts
|
||||||
|
// the results.
|
||||||
func convertEnvironment(source map[string]*string) []string {
|
func convertEnvironment(source map[string]*string) []string {
|
||||||
var output []string
|
var output []string
|
||||||
|
|
||||||
|
@ -605,10 +601,10 @@ func convertEnvironment(source map[string]*string) []string {
|
||||||
case nil:
|
case nil:
|
||||||
output = append(output, name)
|
output = append(output, name)
|
||||||
default:
|
default:
|
||||||
output = append(output, fmt.Sprintf("%s=%s", name, *value))
|
output = append(output, name+"="+*value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort.Strings(output)
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package convert
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -59,7 +58,6 @@ func TestConvertEnvironment(t *testing.T) {
|
||||||
"key": strPtr("value"),
|
"key": strPtr("value"),
|
||||||
}
|
}
|
||||||
env := convertEnvironment(source)
|
env := convertEnvironment(source)
|
||||||
sort.Strings(env)
|
|
||||||
assert.Check(t, is.DeepEqual([]string{"foo=bar", "key=value"}, env))
|
assert.Check(t, is.DeepEqual([]string{"foo=bar", "key=value"}, env))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue