Update kpod commands to use getConfig()

Make getStore() take a config struct from which it pulls the store
options, then update the kpod commands so that they call getConfig()
and pass the config into getStore()

Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
Ryan Cole 2017-07-27 13:18:07 -04:00
parent 0c8f106ee8
commit a8b6f2ad8a
12 changed files with 55 additions and 32 deletions

View file

@ -7,24 +7,13 @@ import (
"github.com/urfave/cli"
)
func getStore(c *cli.Context) (storage.Store, error) {
func getStore(c *libkpod.Config) (storage.Store, error) {
options := storage.DefaultStoreOptions
if c.GlobalIsSet("root") {
options.GraphRoot = c.GlobalString("root")
}
if c.GlobalIsSet("runroot") {
options.RunRoot = c.GlobalString("runroot")
}
options.GraphRoot = c.Root
options.RunRoot = c.RunRoot
options.GraphDriverName = c.Storage
options.GraphDriverOptions = c.StorageOptions
if c.GlobalIsSet("storage-driver") {
options.GraphDriverName = c.GlobalString("storage-driver")
}
if c.GlobalIsSet("storage-opt") {
opts := c.GlobalStringSlice("storage-opt")
if len(opts) > 0 {
options.GraphDriverOptions = opts
}
}
store, err := storage.GetStore(options)
if err != nil {
return nil, err
@ -36,7 +25,7 @@ func getStore(c *cli.Context) (storage.Store, error) {
func getConfig(c *cli.Context) (*libkpod.Config, error) {
config := libkpod.DefaultConfig()
if c.GlobalIsSet("config") {
err := config.FromFile(c.String("config"))
err := config.UpdateFromFile(c.String("config"))
if err != nil {
return config, err
}