2017-05-08 13:36:04 -04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
linting: ST1005: error strings should not be capitalized (stylecheck)
While fixing, also updated errors without placeholders to `errors.New()`, and
updated some code to use pkg/errors if it was already in use in the file.
cli/command/config/inspect.go:59:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/node/inspect.go:61:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/secret/inspect.go:57:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/trust/common.go:77:74: ST1005: error strings should not be capitalized (stylecheck)
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, fmt.Errorf("No signatures or cannot access %s", remote)
^
cli/command/trust/common.go:85:73: ST1005: error strings should not be capitalized (stylecheck)
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, fmt.Errorf("No signers for %s", remote)
^
cli/command/trust/sign.go:137:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("No tag specified for %s", imgRefAndAuth.Name())
^
cli/command/trust/sign.go:151:19: ST1005: error strings should not be capitalized (stylecheck)
return *target, fmt.Errorf("No tag specified")
^
cli/command/trust/signer_add.go:77:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Failed to add signer to: %s", strings.Join(errRepos, ", "))
^
cli/command/trust/signer_remove.go:52:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Error removing signer from: %s", strings.Join(errRepos, ", "))
^
cli/command/trust/signer_remove.go:67:17: ST1005: error strings should not be capitalized (stylecheck)
return false, fmt.Errorf("All signed tags are currently revoked, use docker trust sign to fix")
^
cli/command/trust/signer_remove.go:108:17: ST1005: error strings should not be capitalized (stylecheck)
return false, fmt.Errorf("No signer %s for repository %s", signerName, repoName)
^
opts/hosts.go:89:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", addr)
^
opts/hosts.go:100:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid proto, expected %s: %s", proto, addr)
^
opts/hosts.go:119:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid proto, expected tcp: %s", tryAddr)
^
opts/hosts.go:144:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", tryAddr)
^
opts/hosts.go:155:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", tryAddr)
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-02 18:04:53 -04:00
|
|
|
"errors"
|
2017-05-15 18:23:20 -04:00
|
|
|
"strings"
|
|
|
|
|
2017-05-08 13:36:04 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2017-05-15 18:23:20 -04:00
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
2021-01-18 05:43:29 -05:00
|
|
|
flagsHelper "github.com/docker/cli/cli/flags"
|
2017-05-08 13:36:04 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2019-03-05 17:26:42 -05:00
|
|
|
// InspectOptions contains options for the docker config inspect command.
|
|
|
|
type InspectOptions struct {
|
|
|
|
Names []string
|
|
|
|
Format string
|
|
|
|
Pretty bool
|
2017-05-08 13:36:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func newConfigInspectCommand(dockerCli command.Cli) *cobra.Command {
|
2019-03-05 17:26:42 -05:00
|
|
|
opts := InspectOptions{}
|
2017-05-08 13:36:04 -04:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "inspect [OPTIONS] CONFIG [CONFIG...]",
|
2018-01-04 16:17:56 -05:00
|
|
|
Short: "Display detailed information on one or more configs",
|
2017-05-08 13:36:04 -04:00
|
|
|
Args: cli.RequiresMinArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-03-05 17:26:42 -05:00
|
|
|
opts.Names = args
|
|
|
|
return RunConfigInspect(dockerCli, opts)
|
2017-05-08 13:36:04 -04:00
|
|
|
},
|
2022-03-30 09:27:25 -04:00
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
|
return completeNames(dockerCli)(cmd, args, toComplete)
|
|
|
|
},
|
2017-05-08 13:36:04 -04:00
|
|
|
}
|
|
|
|
|
2022-03-08 08:54:21 -05:00
|
|
|
cmd.Flags().StringVarP(&opts.Format, "format", "f", "", flagsHelper.InspectFormatHelp)
|
2019-03-05 17:26:42 -05:00
|
|
|
cmd.Flags().BoolVar(&opts.Pretty, "pretty", false, "Print the information in a human friendly format")
|
2017-05-08 13:36:04 -04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2019-03-05 17:26:42 -05:00
|
|
|
// RunConfigInspect inspects the given Swarm config.
|
|
|
|
func RunConfigInspect(dockerCli command.Cli, opts InspectOptions) error {
|
2017-05-08 13:36:04 -04:00
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-03-05 17:26:42 -05:00
|
|
|
if opts.Pretty {
|
|
|
|
opts.Format = "pretty"
|
2017-05-15 18:23:20 -04:00
|
|
|
}
|
|
|
|
|
2017-05-08 13:36:04 -04:00
|
|
|
getRef := func(id string) (interface{}, []byte, error) {
|
|
|
|
return client.ConfigInspectWithRaw(ctx, id)
|
|
|
|
}
|
2019-03-05 17:26:42 -05:00
|
|
|
f := opts.Format
|
2017-05-15 18:23:20 -04:00
|
|
|
|
|
|
|
// check if the user is trying to apply a template to the pretty format, which
|
|
|
|
// is not supported
|
|
|
|
if strings.HasPrefix(f, "pretty") && f != "pretty" {
|
linting: ST1005: error strings should not be capitalized (stylecheck)
While fixing, also updated errors without placeholders to `errors.New()`, and
updated some code to use pkg/errors if it was already in use in the file.
cli/command/config/inspect.go:59:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/node/inspect.go:61:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/secret/inspect.go:57:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/trust/common.go:77:74: ST1005: error strings should not be capitalized (stylecheck)
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, fmt.Errorf("No signatures or cannot access %s", remote)
^
cli/command/trust/common.go:85:73: ST1005: error strings should not be capitalized (stylecheck)
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, fmt.Errorf("No signers for %s", remote)
^
cli/command/trust/sign.go:137:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("No tag specified for %s", imgRefAndAuth.Name())
^
cli/command/trust/sign.go:151:19: ST1005: error strings should not be capitalized (stylecheck)
return *target, fmt.Errorf("No tag specified")
^
cli/command/trust/signer_add.go:77:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Failed to add signer to: %s", strings.Join(errRepos, ", "))
^
cli/command/trust/signer_remove.go:52:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Error removing signer from: %s", strings.Join(errRepos, ", "))
^
cli/command/trust/signer_remove.go:67:17: ST1005: error strings should not be capitalized (stylecheck)
return false, fmt.Errorf("All signed tags are currently revoked, use docker trust sign to fix")
^
cli/command/trust/signer_remove.go:108:17: ST1005: error strings should not be capitalized (stylecheck)
return false, fmt.Errorf("No signer %s for repository %s", signerName, repoName)
^
opts/hosts.go:89:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", addr)
^
opts/hosts.go:100:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid proto, expected %s: %s", proto, addr)
^
opts/hosts.go:119:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid proto, expected tcp: %s", tryAddr)
^
opts/hosts.go:144:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", tryAddr)
^
opts/hosts.go:155:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", tryAddr)
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-02 18:04:53 -04:00
|
|
|
return errors.New("cannot supply extra formatting options to the pretty template")
|
2017-05-15 18:23:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
configCtx := formatter.Context{
|
|
|
|
Output: dockerCli.Out(),
|
2018-10-23 11:05:44 -04:00
|
|
|
Format: NewFormat(f, false),
|
2017-05-15 18:23:20 -04:00
|
|
|
}
|
|
|
|
|
2019-03-05 17:26:42 -05:00
|
|
|
if err := InspectFormatWrite(configCtx, opts.Names, getRef); err != nil {
|
2017-05-15 18:23:20 -04:00
|
|
|
return cli.StatusError{StatusCode: 1, Status: err.Error()}
|
|
|
|
}
|
|
|
|
return nil
|
2017-05-08 13:36:04 -04:00
|
|
|
}
|