mirror of
https://github.com/containers/podman.git
synced 2025-09-24 15:25:41 +08:00
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>
This commit is contained in:
@ -5,22 +5,24 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// Value for --remote given on command line
|
||||||
// Was --remote given on command line
|
var remoteFromCLI = struct {
|
||||||
remoteOverride bool
|
Value bool
|
||||||
remoteSync sync.Once
|
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
|
// Use in init() functions as a initialization check
|
||||||
func IsRemote() bool {
|
func IsRemote() bool {
|
||||||
remoteSync.Do(func() {
|
remoteFromCLI.sync.Do(func() {
|
||||||
remote := &cobra.Command{}
|
fs := pflag.NewFlagSet("remote", pflag.ContinueOnError)
|
||||||
remote.Flags().BoolVarP(&remoteOverride, "remote", "r", false, "")
|
fs.BoolVarP(&remoteFromCLI.Value, "remote", "r", false, "")
|
||||||
_ = remote.ParseFlags(os.Args)
|
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
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,10 @@ func WaitContainerReady(p PodmanTestCommon, id string, expStr string, timeout in
|
|||||||
|
|
||||||
// OutputToString formats session output to string
|
// OutputToString formats session output to string
|
||||||
func (s *PodmanSession) OutputToString() string {
|
func (s *PodmanSession) OutputToString() string {
|
||||||
|
if s == nil || s.Out == nil || s.Out.Contents() == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
fields := strings.Fields(string(s.Out.Contents()))
|
fields := strings.Fields(string(s.Out.Contents()))
|
||||||
return strings.Join(fields, " ")
|
return strings.Join(fields, " ")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user