summaryrefslogtreecommitdiff
path: root/cmd/podman/libpodruntime/runtime.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/libpodruntime/runtime.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz
podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2
podman-25a3923b61a5ca014318e6d957f68abd03947297.zip
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the project is more well maintained. There are also some technical reasons as well which extend into our remote client work. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/libpodruntime/runtime.go')
-rw-r--r--cmd/podman/libpodruntime/runtime.go86
1 files changed, 52 insertions, 34 deletions
diff --git a/cmd/podman/libpodruntime/runtime.go b/cmd/podman/libpodruntime/runtime.go
index dca2f5022..60acd1f5b 100644
--- a/cmd/podman/libpodruntime/runtime.go
+++ b/cmd/podman/libpodruntime/runtime.go
@@ -1,15 +1,15 @@
package libpodruntime
import (
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
- "github.com/urfave/cli"
)
// GetRuntime generates a new libpod runtime configured by command line options
-func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
+func GetRuntime(c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
options := []libpod.RuntimeOption{}
storageOpts, volumePath, err := util.GetDefaultStoreOptions()
@@ -17,29 +17,39 @@ func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
return nil, err
}
- if c.IsSet("uidmap") || c.IsSet("gidmap") || c.IsSet("subuidmap") || c.IsSet("subgidmap") {
- mappings, err := util.ParseIDMapping(c.StringSlice("uidmap"), c.StringSlice("gidmap"), c.String("subuidmap"), c.String("subgidmap"))
+ uidmapFlag := c.Flags().Lookup("uidmap")
+ gidmapFlag := c.Flags().Lookup("gidmap")
+ subuidname := c.Flags().Lookup("subuidname")
+ subgidname := c.Flags().Lookup("subgidname")
+ if (uidmapFlag != nil && gidmapFlag != nil && subuidname != nil && subgidname != nil) &&
+ (uidmapFlag.Changed || gidmapFlag.Changed || subuidname.Changed || subgidname.Changed) {
+ uidmapVal, _ := c.Flags().GetStringSlice("uidmap")
+ gidmapVal, _ := c.Flags().GetStringSlice("gidmap")
+ subuidVal, _ := c.Flags().GetString("subuidname")
+ subgidVal, _ := c.Flags().GetString("subgidname")
+ mappings, err := util.ParseIDMapping(uidmapVal, gidmapVal, subuidVal, subgidVal)
if err != nil {
return nil, err
}
storageOpts.UIDMap = mappings.UIDMap
storageOpts.GIDMap = mappings.GIDMap
+
}
- if c.GlobalIsSet("root") {
- storageOpts.GraphRoot = c.GlobalString("root")
+ if c.Flags().Changed("root") {
+ storageOpts.GraphRoot = c.GlobalFlags.Root
}
- if c.GlobalIsSet("runroot") {
- storageOpts.RunRoot = c.GlobalString("runroot")
+ if c.Flags().Changed("runroot") {
+ storageOpts.RunRoot = c.GlobalFlags.Runroot
}
if len(storageOpts.RunRoot) > 50 {
return nil, errors.New("the specified runroot is longer than 50 characters")
}
- if c.GlobalIsSet("storage-driver") {
- storageOpts.GraphDriverName = c.GlobalString("storage-driver")
+ if c.Flags().Changed("storage-driver") {
+ storageOpts.GraphDriverName = c.GlobalFlags.StorageDriver
}
- if c.GlobalIsSet("storage-opt") {
- storageOpts.GraphDriverOptions = c.GlobalStringSlice("storage-opt")
+ if c.Flags().Changed("storage-opt") {
+ storageOpts.GraphDriverOptions = c.GlobalFlags.StorageOpts
}
options = append(options, libpod.WithStorageConfig(storageOpts))
@@ -47,23 +57,23 @@ func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
// TODO CLI flags for image config?
// TODO CLI flag for signature policy?
- if c.GlobalIsSet("namespace") {
- options = append(options, libpod.WithNamespace(c.GlobalString("namespace")))
+ if len(c.GlobalFlags.Namespace) > 0 {
+ options = append(options, libpod.WithNamespace(c.GlobalFlags.Namespace))
}
- if c.GlobalIsSet("runtime") {
- options = append(options, libpod.WithOCIRuntime(c.GlobalString("runtime")))
+ if c.Flags().Changed("runtime") {
+ options = append(options, libpod.WithOCIRuntime(c.GlobalFlags.Runtime))
}
- if c.GlobalIsSet("conmon") {
- options = append(options, libpod.WithConmonPath(c.GlobalString("conmon")))
+ if c.Flags().Changed("conmon") {
+ options = append(options, libpod.WithConmonPath(c.GlobalFlags.ConmonPath))
}
- if c.GlobalIsSet("tmpdir") {
- options = append(options, libpod.WithTmpDir(c.GlobalString("tmpdir")))
+ if c.Flags().Changed("tmpdir") {
+ options = append(options, libpod.WithTmpDir(c.GlobalFlags.TmpDir))
}
- if c.GlobalIsSet("cgroup-manager") {
- options = append(options, libpod.WithCgroupManager(c.GlobalString("cgroup-manager")))
+ if c.Flags().Changed("cgroup-manager") {
+ options = append(options, libpod.WithCgroupManager(c.GlobalFlags.CGroupManager))
} else {
if rootless.IsRootless() {
options = append(options, libpod.WithCgroupManager("cgroupfs"))
@@ -73,29 +83,37 @@ func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
// TODO flag to set libpod static dir?
// TODO flag to set libpod tmp dir?
- if c.GlobalIsSet("cni-config-dir") {
- options = append(options, libpod.WithCNIConfigDir(c.GlobalString("cni-config-dir")))
+ if c.Flags().Changed("cni-config-dir") {
+ options = append(options, libpod.WithCNIConfigDir(c.GlobalFlags.CniConfigDir))
}
- if c.GlobalIsSet("default-mounts-file") {
- options = append(options, libpod.WithDefaultMountsFile(c.GlobalString("default-mounts-file")))
+ if c.Flags().Changed("default-mounts-file") {
+ options = append(options, libpod.WithDefaultMountsFile(c.GlobalFlags.DefaultMountsFile))
}
- if c.GlobalIsSet("hooks-dir") {
- options = append(options, libpod.WithHooksDir(c.GlobalStringSlice("hooks-dir")...))
+ if c.Flags().Changed("hooks-dir") {
+ options = append(options, libpod.WithHooksDir(c.GlobalFlags.HooksDir...))
}
// TODO flag to set CNI plugins dir?
+ // TODO I dont think these belong here?
+ // Will follow up with a different PR to address
+ //
// Pod create options
- if c.IsSet("infra-image") {
- options = append(options, libpod.WithDefaultInfraImage(c.String("infra-image")))
+
+ infraImageFlag := c.Flags().Lookup("infra-image")
+ if infraImageFlag != nil && infraImageFlag.Changed {
+ infraImage, _ := c.Flags().GetString("infra-image")
+ options = append(options, libpod.WithDefaultInfraImage(infraImage))
}
- if c.IsSet("infra-command") {
- options = append(options, libpod.WithDefaultInfraCommand(c.String("infra-command")))
+ infraCommandFlag := c.Flags().Lookup("infra-command")
+ if infraCommandFlag != nil && infraImageFlag.Changed {
+ infraCommand, _ := c.Flags().GetString("infra-command")
+ options = append(options, libpod.WithDefaultInfraCommand(infraCommand))
}
options = append(options, libpod.WithVolumePath(volumePath))
- if c.IsSet("config") {
- return libpod.NewRuntimeFromConfig(c.String("config"), options...)
+ if c.Flags().Changed("config") {
+ return libpod.NewRuntimeFromConfig(c.GlobalFlags.Config, options...)
}
return libpod.NewRuntime(options...)
}