cli/command/context: minor cleanups
- use dockerCLI with Go's standard camelCase casing. - suppress some errors to make my IDE and linters happier Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c462eaee11
commit
82e2efbbf7
@ -34,11 +34,11 @@ func longCreateDescription() string {
|
|||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
buf.WriteString("Create a context\n\nDocker endpoint config:\n\n")
|
buf.WriteString("Create a context\n\nDocker endpoint config:\n\n")
|
||||||
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
|
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
|
||||||
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
|
_, _ = fmt.Fprintln(tw, "NAME\tDESCRIPTION")
|
||||||
for _, d := range dockerConfigKeysDescriptions {
|
for _, d := range dockerConfigKeysDescriptions {
|
||||||
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
|
_, _ = fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
|
||||||
}
|
}
|
||||||
tw.Flush()
|
_ = tw.Flush()
|
||||||
buf.WriteString("\nExample:\n\n$ docker context create my-context --description \"some description\" --docker \"host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\"\n")
|
buf.WriteString("\nExample:\n\n$ docker context create my-context --description \"some description\" --docker \"host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\"\n")
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
@ -79,8 +79,8 @@ func RunCreate(dockerCLI command.Cli, o *CreateOptions) error {
|
|||||||
err = createNewContext(s, o)
|
err = createNewContext(s, o)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Fprintln(dockerCLI.Out(), o.Name)
|
_, _ = fmt.Fprintln(dockerCLI.Out(), o.Name)
|
||||||
fmt.Fprintf(dockerCLI.Err(), "Successfully created context %q\n", o.Name)
|
_, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully created context %q\n", o.Name)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func RunImport(dockerCli command.Cli, name string, source string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(dockerCli.Out(), name)
|
_, _ = fmt.Fprintln(dockerCli.Out(), name)
|
||||||
fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
|
_, _ = fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,11 @@ func longUpdateDescription() string {
|
|||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
buf.WriteString("Update a context\n\nDocker endpoint config:\n\n")
|
buf.WriteString("Update a context\n\nDocker endpoint config:\n\n")
|
||||||
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
|
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
|
||||||
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
|
_, _ = fmt.Fprintln(tw, "NAME\tDESCRIPTION")
|
||||||
for _, d := range dockerConfigKeysDescriptions {
|
for _, d := range dockerConfigKeysDescriptions {
|
||||||
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
|
_, _ = fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
|
||||||
}
|
}
|
||||||
tw.Flush()
|
_ = tw.Flush()
|
||||||
buf.WriteString("\nExample:\n\n$ docker context update my-context --description \"some description\" --docker \"host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\"\n")
|
buf.WriteString("\nExample:\n\n$ docker context update my-context --description \"some description\" --docker \"host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\"\n")
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
@ -93,8 +93,8 @@ func RunUpdate(dockerCLI command.Cli, o *UpdateOptions) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(dockerCLI.Out(), o.Name)
|
_, _ = fmt.Fprintln(dockerCLI.Out(), o.Name)
|
||||||
fmt.Fprintf(dockerCLI.Err(), "Successfully updated context %q\n", o.Name)
|
_, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully updated context %q\n", o.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,19 +24,19 @@ func newUseCommand(dockerCli command.Cli) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunUse set the current Docker context
|
// RunUse set the current Docker context
|
||||||
func RunUse(dockerCli command.Cli, name string) error {
|
func RunUse(dockerCLI command.Cli, name string) error {
|
||||||
// configValue uses an empty string for "default"
|
// configValue uses an empty string for "default"
|
||||||
var configValue string
|
var configValue string
|
||||||
if name != command.DefaultContextName {
|
if name != command.DefaultContextName {
|
||||||
if err := store.ValidateContextName(name); err != nil {
|
if err := store.ValidateContextName(name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil {
|
if _, err := dockerCLI.ContextStore().GetMetadata(name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
configValue = name
|
configValue = name
|
||||||
}
|
}
|
||||||
dockerConfig := dockerCli.ConfigFile()
|
dockerConfig := dockerCLI.ConfigFile()
|
||||||
// Avoid updating the config-file if nothing changed. This also prevents
|
// Avoid updating the config-file if nothing changed. This also prevents
|
||||||
// creating the file and config-directory if the default is used and
|
// creating the file and config-directory if the default is used and
|
||||||
// no config-file existed yet.
|
// no config-file existed yet.
|
||||||
@ -46,10 +46,10 @@ func RunUse(dockerCli command.Cli, name string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintln(dockerCli.Out(), name)
|
_, _ = fmt.Fprintln(dockerCLI.Out(), name)
|
||||||
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
|
_, _ = fmt.Fprintf(dockerCLI.Err(), "Current context is now %q\n", name)
|
||||||
if name != command.DefaultContextName && os.Getenv(client.EnvOverrideHost) != "" {
|
if name != command.DefaultContextName && os.Getenv(client.EnvOverrideHost) != "" {
|
||||||
fmt.Fprintf(dockerCli.Err(), "Warning: %[1]s environment variable overrides the active context. "+
|
_, _ = fmt.Fprintf(dockerCLI.Err(), "Warning: %[1]s environment variable overrides the active context. "+
|
||||||
"To use %[2]q, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost, name)
|
"To use %[2]q, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost, name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user