diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-03 11:30:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-03 11:30:51 +0200 |
commit | a7809fabe508e26c527490e700a1703ef923bd3b (patch) | |
tree | 2c3e83fa62f6b98b394123d1c73e321e40041c95 /pkg/util | |
parent | 4877e6a947beff12f7f927978f04cffc11377007 (diff) | |
parent | a477a8ff755e2807d0745b207d6a5bf57de58e4c (diff) | |
download | podman-a7809fabe508e26c527490e700a1703ef923bd3b.tar.gz podman-a7809fabe508e26c527490e700a1703ef923bd3b.tar.bz2 podman-a7809fabe508e26c527490e700a1703ef923bd3b.zip |
Merge pull request #2905 from QiWang19/globalvar
Add variable for global flags to runlabel
Diffstat (limited to 'pkg/util')
-rw-r--r-- | pkg/util/utils.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 14b0c2b55..2a52e5129 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -10,10 +10,12 @@ import ( "github.com/BurntSushi/toml" "github.com/containers/image/types" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/storage" "github.com/containers/storage/pkg/idtools" "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" + "github.com/spf13/pflag" "golang.org/x/crypto/ssh/terminal" ) @@ -252,3 +254,32 @@ func ParseInputTime(inputTime string) (time.Time, error) { } return time.Now().Add(-duration), nil } + +// GetGlobalOpts checks all global flags and generates the command string +func GetGlobalOpts(c *cliconfig.RunlabelValues) string { + globalFlags := map[string]bool{ + "cgroup-manager": true, "cni-config-dir": true, "conmon": true, "default-mounts-file": true, + "hooks-dir": true, "namespace": true, "root": true, "runroot": true, + "runtime": true, "storage-driver": true, "storage-opt": true, "syslog": true, + "trace": true, "network-cmd-path": true, "config": true, "cpu-profile": true, + "log-level": true, "tmpdir": true} + const stringSliceType string = "stringSlice" + + var optsCommand []string + c.PodmanCommand.Command.Flags().VisitAll(func(f *pflag.Flag) { + if !f.Changed { + return + } + if _, exist := globalFlags[f.Name]; exist { + if f.Value.Type() == stringSliceType { + flagValue := strings.TrimSuffix(strings.TrimPrefix(f.Value.String(), "["), "]") + for _, value := range strings.Split(flagValue, ",") { + optsCommand = append(optsCommand, fmt.Sprintf("--%s %s", f.Name, value)) + } + } else { + optsCommand = append(optsCommand, fmt.Sprintf("--%s %s", f.Name, f.Value.String())) + } + } + }) + return strings.Join(optsCommand, " ") +} |