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:
Sebastiaan van Stijn 2025-02-01 22:32:30 +01:00
parent c462eaee11
commit 82e2efbbf7
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
4 changed files with 18 additions and 18 deletions

View File

@ -34,11 +34,11 @@ func longCreateDescription() string {
buf := bytes.NewBuffer(nil)
buf.WriteString("Create a context\n\nDocker endpoint config:\n\n")
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
_, _ = fmt.Fprintln(tw, "NAME\tDESCRIPTION")
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")
return buf.String()
}
@ -79,8 +79,8 @@ func RunCreate(dockerCLI command.Cli, o *CreateOptions) error {
err = createNewContext(s, o)
}
if err == nil {
fmt.Fprintln(dockerCLI.Out(), o.Name)
fmt.Fprintf(dockerCLI.Err(), "Successfully created context %q\n", o.Name)
_, _ = fmt.Fprintln(dockerCLI.Out(), o.Name)
_, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully created context %q\n", o.Name)
}
return err
}

View File

@ -45,7 +45,7 @@ func RunImport(dockerCli command.Cli, name string, source string) error {
return err
}
fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
_, _ = fmt.Fprintln(dockerCli.Out(), name)
_, _ = fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
return nil
}

View File

@ -24,11 +24,11 @@ func longUpdateDescription() string {
buf := bytes.NewBuffer(nil)
buf.WriteString("Update a context\n\nDocker endpoint config:\n\n")
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
_, _ = fmt.Fprintln(tw, "NAME\tDESCRIPTION")
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")
return buf.String()
}
@ -93,8 +93,8 @@ func RunUpdate(dockerCLI command.Cli, o *UpdateOptions) error {
}
}
fmt.Fprintln(dockerCLI.Out(), o.Name)
fmt.Fprintf(dockerCLI.Err(), "Successfully updated context %q\n", o.Name)
_, _ = fmt.Fprintln(dockerCLI.Out(), o.Name)
_, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully updated context %q\n", o.Name)
return nil
}

View File

@ -24,19 +24,19 @@ func newUseCommand(dockerCli command.Cli) *cobra.Command {
}
// 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"
var configValue string
if name != command.DefaultContextName {
if err := store.ValidateContextName(name); err != nil {
return err
}
if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil {
if _, err := dockerCLI.ContextStore().GetMetadata(name); err != nil {
return err
}
configValue = name
}
dockerConfig := dockerCli.ConfigFile()
dockerConfig := dockerCLI.ConfigFile()
// Avoid updating the config-file if nothing changed. This also prevents
// creating the file and config-directory if the default is used and
// no config-file existed yet.
@ -46,10 +46,10 @@ func RunUse(dockerCli command.Cli, name string) error {
return err
}
}
fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
_, _ = fmt.Fprintln(dockerCLI.Out(), name)
_, _ = fmt.Fprintf(dockerCLI.Err(), "Current context is now %q\n", name)
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)
}
return nil