mirror of https://github.com/docker/cli.git
Add unparam linter
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
3bf0317fea
commit
3e3934c19f
|
@ -61,16 +61,14 @@ func parseRun(args []string) (*container.Config, *container.HostConfig, *network
|
||||||
return containerConfig.Config, containerConfig.HostConfig, containerConfig.NetworkingConfig, err
|
return containerConfig.Config, containerConfig.HostConfig, containerConfig.NetworkingConfig, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsetest(t *testing.T, args string) (*container.Config, *container.HostConfig, error) {
|
func parseMustError(t *testing.T, args string) {
|
||||||
config, hostConfig, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
|
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
|
||||||
return config, hostConfig, err
|
assert.Error(t, err, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) {
|
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) {
|
||||||
config, hostConfig, err := parsetest(t, args)
|
config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
|
||||||
if err != nil {
|
assert.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
return config, hostConfig
|
return config, hostConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +84,6 @@ func TestParseRunLinks(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: gocyclo
|
|
||||||
func TestParseRunAttach(t *testing.T) {
|
func TestParseRunAttach(t *testing.T) {
|
||||||
if config, _ := mustParse(t, "-a stdin"); !config.AttachStdin || config.AttachStdout || config.AttachStderr {
|
if config, _ := mustParse(t, "-a stdin"); !config.AttachStdin || config.AttachStdout || config.AttachStderr {
|
||||||
t.Fatalf("Error parsing attach flags. Expect only Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr)
|
t.Fatalf("Error parsing attach flags. Expect only Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr)
|
||||||
|
@ -103,31 +100,17 @@ func TestParseRunAttach(t *testing.T) {
|
||||||
if config, _ := mustParse(t, "-i"); !config.AttachStdin || !config.AttachStdout || !config.AttachStderr {
|
if config, _ := mustParse(t, "-i"); !config.AttachStdin || !config.AttachStdout || !config.AttachStderr {
|
||||||
t.Fatalf("Error parsing attach flags. Expect Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr)
|
t.Fatalf("Error parsing attach flags. Expect Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if _, _, err := parsetest(t, "-a"); err == nil {
|
func TestParseRunWithInvalidArgs(t *testing.T) {
|
||||||
t.Fatal("Error parsing attach flags, `-a` should be an error but is not")
|
parseMustError(t, "-a")
|
||||||
}
|
parseMustError(t, "-a invalid")
|
||||||
if _, _, err := parsetest(t, "-a invalid"); err == nil {
|
parseMustError(t, "-a invalid -a stdout")
|
||||||
t.Fatal("Error parsing attach flags, `-a invalid` should be an error but is not")
|
parseMustError(t, "-a stdout -a stderr -d")
|
||||||
}
|
parseMustError(t, "-a stdin -d")
|
||||||
if _, _, err := parsetest(t, "-a invalid -a stdout"); err == nil {
|
parseMustError(t, "-a stdout -d")
|
||||||
t.Fatal("Error parsing attach flags, `-a stdout -a invalid` should be an error but is not")
|
parseMustError(t, "-a stderr -d")
|
||||||
}
|
parseMustError(t, "-d --rm")
|
||||||
if _, _, err := parsetest(t, "-a stdout -a stderr -d"); err == nil {
|
|
||||||
t.Fatal("Error parsing attach flags, `-a stdout -a stderr -d` should be an error but is not")
|
|
||||||
}
|
|
||||||
if _, _, err := parsetest(t, "-a stdin -d"); err == nil {
|
|
||||||
t.Fatal("Error parsing attach flags, `-a stdin -d` should be an error but is not")
|
|
||||||
}
|
|
||||||
if _, _, err := parsetest(t, "-a stdout -d"); err == nil {
|
|
||||||
t.Fatal("Error parsing attach flags, `-a stdout -d` should be an error but is not")
|
|
||||||
}
|
|
||||||
if _, _, err := parsetest(t, "-a stderr -d"); err == nil {
|
|
||||||
t.Fatal("Error parsing attach flags, `-a stderr -d` should be an error but is not")
|
|
||||||
}
|
|
||||||
if _, _, err := parsetest(t, "-d --rm"); err == nil {
|
|
||||||
t.Fatal("Error parsing attach flags, `-d --rm` should be an error but is not")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
|
|
|
@ -106,7 +106,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
|
||||||
closeChan <- err
|
closeChan <- err
|
||||||
}
|
}
|
||||||
for _, container := range cs {
|
for _, container := range cs {
|
||||||
s := formatter.NewContainerStats(container.ID[:12], daemonOSType)
|
s := formatter.NewContainerStats(container.ID[:12])
|
||||||
if cStats.add(s) {
|
if cStats.add(s) {
|
||||||
waitFirst.Add(1)
|
waitFirst.Add(1)
|
||||||
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
||||||
|
@ -123,7 +123,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
|
||||||
eh := command.InitEventHandler()
|
eh := command.InitEventHandler()
|
||||||
eh.Handle("create", func(e events.Message) {
|
eh.Handle("create", func(e events.Message) {
|
||||||
if opts.all {
|
if opts.all {
|
||||||
s := formatter.NewContainerStats(e.ID[:12], daemonOSType)
|
s := formatter.NewContainerStats(e.ID[:12])
|
||||||
if cStats.add(s) {
|
if cStats.add(s) {
|
||||||
waitFirst.Add(1)
|
waitFirst.Add(1)
|
||||||
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
||||||
|
@ -132,7 +132,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
|
||||||
})
|
})
|
||||||
|
|
||||||
eh.Handle("start", func(e events.Message) {
|
eh.Handle("start", func(e events.Message) {
|
||||||
s := formatter.NewContainerStats(e.ID[:12], daemonOSType)
|
s := formatter.NewContainerStats(e.ID[:12])
|
||||||
if cStats.add(s) {
|
if cStats.add(s) {
|
||||||
waitFirst.Add(1)
|
waitFirst.Add(1)
|
||||||
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
||||||
|
@ -158,7 +158,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
|
||||||
// Artificially send creation events for the containers we were asked to
|
// Artificially send creation events for the containers we were asked to
|
||||||
// monitor (same code path than we use when monitoring all containers).
|
// monitor (same code path than we use when monitoring all containers).
|
||||||
for _, name := range opts.containers {
|
for _, name := range opts.containers {
|
||||||
s := formatter.NewContainerStats(name, daemonOSType)
|
s := formatter.NewContainerStats(name)
|
||||||
if cStats.add(s) {
|
if cStats.add(s) {
|
||||||
waitFirst.Add(1)
|
waitFirst.Add(1)
|
||||||
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst)
|
||||||
|
|
|
@ -109,10 +109,8 @@ func NewStatsFormat(source, osType string) Format {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainerStats returns a new ContainerStats entity and sets in it the given name
|
// NewContainerStats returns a new ContainerStats entity and sets in it the given name
|
||||||
func NewContainerStats(container, osType string) *ContainerStats {
|
func NewContainerStats(container string) *ContainerStats {
|
||||||
return &ContainerStats{
|
return &ContainerStats{StatsEntry: StatsEntry{Container: container}}
|
||||||
StatsEntry: StatsEntry{Container: container},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStatsWrite renders the context for a list of containers statistics
|
// ContainerStatsWrite renders the context for a list of containers statistics
|
||||||
|
|
|
@ -92,7 +92,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not fetch unlock key")
|
return errors.Wrap(err, "could not fetch unlock key")
|
||||||
}
|
}
|
||||||
printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey)
|
printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,6 +2,7 @@ package swarm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
@ -74,16 +75,15 @@ func runUnlockKey(dockerCli command.Cli, opts unlockKeyOptions) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey)
|
printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printUnlockCommand(ctx context.Context, dockerCli command.Cli, unlockKey string) {
|
func printUnlockCommand(out io.Writer, unlockKey string) {
|
||||||
if len(unlockKey) > 0 {
|
if len(unlockKey) > 0 {
|
||||||
fmt.Fprintf(dockerCli.Out(), "To unlock a swarm manager after it restarts, "+
|
fmt.Fprintf(out, "To unlock a swarm manager after it restarts, "+
|
||||||
"run the `docker swarm unlock`\ncommand and provide the following key:\n\n %s\n\n"+
|
"run the `docker swarm unlock`\ncommand and provide the following key:\n\n %s\n\n"+
|
||||||
"Please remember to store this key in a password manager, since without it you\n"+
|
"Please remember to store this key in a password manager, since without it you\n"+
|
||||||
"will not be able to restart the manager.\n", unlockKey)
|
"will not be able to restart the manager.\n", unlockKey)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ func runUpdate(dockerCli command.Cli, flags *pflag.FlagSet, opts swarmOptions) e
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not fetch unlock key")
|
return errors.Wrap(err, "could not fetch unlock key")
|
||||||
}
|
}
|
||||||
printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey)
|
printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -18,11 +18,11 @@ func (c *FakeClient) NetworkConnect(ctx context.Context, networkID, container st
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkCreate fakes creating a network
|
// NetworkCreate fakes creating a network
|
||||||
func (c *FakeClient) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
func (c *FakeClient) NetworkCreate(_ context.Context, _ string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
||||||
return types.NetworkCreateResponse{}, nil
|
return types.NetworkCreateResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkDisconnect fakes disconencting from a network
|
// NetworkDisconnect fakes disconnecting from a network
|
||||||
func (c *FakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error {
|
func (c *FakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,12 @@ func (c *FakeClient) NetworkInspect(ctx context.Context, networkID string, optio
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkInspectWithRaw fakes inspecting a network with a raw response
|
// NetworkInspectWithRaw fakes inspecting a network with a raw response
|
||||||
func (c *FakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
|
func (c *FakeClient) NetworkInspectWithRaw(_ context.Context, _ string, _ types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
|
||||||
return types.NetworkResource{}, nil, nil
|
return types.NetworkResource{}, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkList fakes listing networks
|
// NetworkList fakes listing networks
|
||||||
func (c *FakeClient) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
|
func (c *FakeClient) NetworkList(_ context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,6 @@ func (c *FakeClient) NetworkRemove(ctx context.Context, networkID string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworksPrune fakes pruning networks
|
// NetworksPrune fakes pruning networks
|
||||||
func (c *FakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) {
|
func (c *FakeClient) NetworksPrune(_ context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) {
|
||||||
return types.NetworksPruneReport{}, nil
|
return types.NetworksPruneReport{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,14 +66,14 @@ func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandle
|
||||||
if _, err := io.WriteString(f, filePrepender(filename)); err != nil {
|
if _, err := io.WriteString(f, filePrepender(filename)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := GenYamlCustom(cmd, f, linkHandler); err != nil {
|
if err := GenYamlCustom(cmd, f); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenYamlCustom creates custom yaml output
|
// GenYamlCustom creates custom yaml output
|
||||||
func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
|
func GenYamlCustom(cmd *cobra.Command, w io.Writer) error {
|
||||||
cliDoc := cmdDoc{}
|
cliDoc := cmdDoc{}
|
||||||
cliDoc.Name = cmd.CommandPath()
|
cliDoc.Name = cmd.CommandPath()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"Vendor": true,
|
"Vendor": true,
|
||||||
"Deadline": "3m",
|
"Deadline": "5m",
|
||||||
"Sort": ["linter", "severity", "path"],
|
"Sort": ["linter", "severity", "path"],
|
||||||
"Exclude": ["cli/compose/schema/bindata.go"],
|
"Exclude": ["cli/compose/schema/bindata.go"],
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
"lll",
|
"lll",
|
||||||
"misspell",
|
"misspell",
|
||||||
"unconvert",
|
"unconvert",
|
||||||
|
"unparam",
|
||||||
"unused",
|
"unused",
|
||||||
"vet"
|
"vet"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue