summaryrefslogtreecommitdiff
path: root/cmd/podman/registry/remote.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-08-05 22:57:48 +0200
committerGitHub <noreply@github.com>2020-08-05 22:57:48 +0200
commita94863504166ad6fc9f31847e84b71cc32fcd09f (patch)
treee541490175eb56692749365cd1d9d927fdd6fc18 /cmd/podman/registry/remote.go
parentbae6d5ddafb9d293702fda368587caae22fc3c80 (diff)
parent98da2fa80657fecb6b083eaf68974d2ee2f84e6a (diff)
downloadpodman-a94863504166ad6fc9f31847e84b71cc32fcd09f.tar.gz
podman-a94863504166ad6fc9f31847e84b71cc32fcd09f.tar.bz2
podman-a94863504166ad6fc9f31847e84b71cc32fcd09f.zip
Merge pull request #7212 from jwhonce/issues/7211
Refactor parsing to not require --remote to be first flag
Diffstat (limited to 'cmd/podman/registry/remote.go')
-rw-r--r--cmd/podman/registry/remote.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/cmd/podman/registry/remote.go b/cmd/podman/registry/remote.go
index 7dbdd3824..9b7523ac0 100644
--- a/cmd/podman/registry/remote.go
+++ b/cmd/podman/registry/remote.go
@@ -5,22 +5,24 @@ import (
"sync"
"github.com/containers/podman/v2/pkg/domain/entities"
- "github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
-var (
- // Was --remote given on command line
- remoteOverride bool
- remoteSync sync.Once
-)
+// Value for --remote given on command line
+var remoteFromCLI = struct {
+ Value bool
+ sync sync.Once
+}{}
-// IsRemote returns true if podman was built to run remote
+// IsRemote returns true if podman was built to run remote or --remote flag given on CLI
// Use in init() functions as a initialization check
func IsRemote() bool {
- remoteSync.Do(func() {
- remote := &cobra.Command{}
- remote.Flags().BoolVarP(&remoteOverride, "remote", "r", false, "")
- _ = remote.ParseFlags(os.Args)
+ remoteFromCLI.sync.Do(func() {
+ fs := pflag.NewFlagSet("remote", pflag.ContinueOnError)
+ fs.BoolVarP(&remoteFromCLI.Value, "remote", "r", false, "")
+ fs.ParseErrorsWhitelist.UnknownFlags = true
+ fs.SetInterspersed(false)
+ _ = fs.Parse(os.Args[1:])
})
- return podmanOptions.EngineMode == entities.TunnelMode || remoteOverride
+ return podmanOptions.EngineMode == entities.TunnelMode || remoteFromCLI.Value
}