diff options
author | Jhon Honce <jhonce@redhat.com> | 2020-08-03 15:41:25 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2020-08-05 10:19:44 -0700 |
commit | 98da2fa80657fecb6b083eaf68974d2ee2f84e6a (patch) | |
tree | 713bc5b261e4f1c1ddd9ef71f3392238b62ddb22 | |
parent | d1aaf3362204f860267e2bb58ec419b25edc5800 (diff) | |
download | podman-98da2fa80657fecb6b083eaf68974d2ee2f84e6a.tar.gz podman-98da2fa80657fecb6b083eaf68974d2ee2f84e6a.tar.bz2 podman-98da2fa80657fecb6b083eaf68974d2ee2f84e6a.zip |
Refactor parsing to not require --remote to be first
Use cobra.Command.FParseErrWhitelist to no longer require --remote to be
the first argument in flags when using CLI
Signed-off-by: Jhon Honce <jhonce@redhat.com>
-rw-r--r-- | cmd/podman/registry/remote.go | 26 | ||||
-rw-r--r-- | test/utils/utils.go | 4 |
2 files changed, 18 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 } diff --git a/test/utils/utils.go b/test/utils/utils.go index 2c454f532..b279a7084 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -207,6 +207,10 @@ func WaitContainerReady(p PodmanTestCommon, id string, expStr string, timeout in // OutputToString formats session output to string func (s *PodmanSession) OutputToString() string { + if s == nil || s.Out == nil || s.Out.Contents() == nil { + return "" + } + fields := strings.Fields(string(s.Out.Contents())) return strings.Join(fields, " ") } |