summaryrefslogtreecommitdiff
path: root/pkg/adapter
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-01-13 13:01:45 +0100
committerValentin Rothberg <rothberg@redhat.com>2020-01-13 14:27:02 +0100
commit67165b76753f65b6f58d471f314678ae12a4c722 (patch)
tree72580ee08e5d9d2e57b97a7293deaf8a2a0f2e67 /pkg/adapter
parent270d892c3d77de4fd8e6341193175c0572fb5f99 (diff)
downloadpodman-67165b76753f65b6f58d471f314678ae12a4c722.tar.gz
podman-67165b76753f65b6f58d471f314678ae12a4c722.tar.bz2
podman-67165b76753f65b6f58d471f314678ae12a4c722.zip
make lint: enable gocritic
`gocritic` is a powerful linter that helps in preventing certain kinds of errors as well as enforcing a coding style. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/adapter')
-rw-r--r--pkg/adapter/containers.go16
-rw-r--r--pkg/adapter/runtime.go7
-rw-r--r--pkg/adapter/shortcuts/shortcuts.go7
3 files changed, 17 insertions, 13 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index fdd9f6ab3..4e6bcfaa7 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -609,11 +609,12 @@ func (r *LocalRuntime) Restore(ctx context.Context, c *cliconfig.RestoreValues)
return state == define.ContainerStateExited
})
- if c.Import != "" {
+ switch {
+ case c.Import != "":
containers, err = crImportCheckpoint(ctx, r.Runtime, c.Import, c.Name)
- } else if c.All {
+ case c.All:
containers, err = r.GetContainers(filterFuncs...)
- } else {
+ default:
containers, err = shortcuts.GetContainersByContext(false, c.Latest, c.InputArgs, r.Runtime)
}
if err != nil {
@@ -835,25 +836,26 @@ func (r *LocalRuntime) Restart(ctx context.Context, c *cliconfig.RestartValues)
inputTimeout := c.Timeout
// Handle --latest
- if c.Latest {
+ switch {
+ case c.Latest:
lastCtr, err := r.Runtime.GetLatestContainer()
if err != nil {
return nil, nil, errors.Wrapf(err, "unable to get latest container")
}
restartContainers = append(restartContainers, lastCtr)
- } else if c.Running {
+ case c.Running:
containers, err = r.GetRunningContainers()
if err != nil {
return nil, nil, err
}
restartContainers = append(restartContainers, containers...)
- } else if c.All {
+ case c.All:
containers, err = r.Runtime.GetAllContainers()
if err != nil {
return nil, nil, err
}
restartContainers = append(restartContainers, containers...)
- } else {
+ default:
for _, id := range c.InputArgs {
ctr, err := r.Runtime.LookupContainer(id)
if err != nil {
diff --git a/pkg/adapter/runtime.go b/pkg/adapter/runtime.go
index 5f880e807..3be65a03e 100644
--- a/pkg/adapter/runtime.go
+++ b/pkg/adapter/runtime.go
@@ -407,7 +407,8 @@ func (r *LocalRuntime) Events(c *cliconfig.EventValues) error {
}
w := bufio.NewWriter(os.Stdout)
for event := range eventChannel {
- if c.Format == formats.JSONString {
+ switch {
+ case c.Format == formats.JSONString:
jsonStr, err := event.ToJSONString()
if err != nil {
return errors.Wrapf(err, "unable to format json")
@@ -415,11 +416,11 @@ func (r *LocalRuntime) Events(c *cliconfig.EventValues) error {
if _, err := w.Write([]byte(jsonStr)); err != nil {
return err
}
- } else if len(c.Format) > 0 {
+ case len(c.Format) > 0:
if err := tmpl.Execute(w, event); err != nil {
return err
}
- } else {
+ default:
if _, err := w.Write([]byte(event.ToHumanReadable())); err != nil {
return err
}
diff --git a/pkg/adapter/shortcuts/shortcuts.go b/pkg/adapter/shortcuts/shortcuts.go
index 4f6cfd6a3..8a8459c6c 100644
--- a/pkg/adapter/shortcuts/shortcuts.go
+++ b/pkg/adapter/shortcuts/shortcuts.go
@@ -42,12 +42,13 @@ func GetContainersByContext(all, latest bool, names []string, runtime *libpod.Ru
var ctr *libpod.Container
ctrs = []*libpod.Container{}
- if all {
+ switch {
+ case all:
ctrs, err = runtime.GetAllContainers()
- } else if latest {
+ case latest:
ctr, err = runtime.GetLatestContainer()
ctrs = append(ctrs, ctr)
- } else {
+ default:
for _, n := range names {
ctr, e := runtime.LookupContainer(n)
if e != nil {