Skip to content

Commit

Permalink
Merge pull request #7212 from jwhonce/issues/7211
Browse files Browse the repository at this point in the history
Refactor parsing to not require --remote to be first flag
  • Loading branch information
openshift-merge-robot authored Aug 5, 2020
2 parents bae6d5d + 98da2fa commit a948635
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 14 additions & 12 deletions cmd/podman/registry/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
}
Expand Down

0 comments on commit a948635

Please sign in to comment.