cri-o/cmd/kpod/common.go
Ryan Cole 08c3d241a4 Add format functions
Add functions to go templates such as truncating a field.  Also add
the table keyword, which, if placed at the beginning of a format string,
adds headers to the output

Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
2017-08-16 15:45:13 -04:00

63 lines
1.4 KiB
Go

package main
import (
"strings"
is "github.com/containers/image/storage"
"github.com/containers/storage"
"github.com/fatih/camelcase"
"github.com/kubernetes-incubator/cri-o/libkpod"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func getStore(c *libkpod.Config) (storage.Store, error) {
options := storage.DefaultStoreOptions
options.GraphRoot = c.Root
options.RunRoot = c.RunRoot
options.GraphDriverName = c.Storage
options.GraphDriverOptions = c.StorageOptions
store, err := storage.GetStore(options)
if err != nil {
return nil, err
}
is.Transport.SetStore(store)
return store, nil
}
func getConfig(c *cli.Context) (*libkpod.Config, error) {
config := libkpod.DefaultConfig()
if c.GlobalIsSet("config") {
err := config.UpdateFromFile(c.String("config"))
if err != nil {
return config, err
}
}
if c.GlobalIsSet("root") {
config.Root = c.GlobalString("root")
}
if c.GlobalIsSet("runroot") {
config.RunRoot = c.GlobalString("runroot")
}
if c.GlobalIsSet("storage-driver") {
config.Storage = c.GlobalString("storage-driver")
}
if c.GlobalIsSet("storage-opt") {
opts := c.GlobalStringSlice("storage-opt")
if len(opts) > 0 {
config.StorageOptions = opts
}
}
if c.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
return config, nil
}
func splitCamelCase(src string) string {
entries := camelcase.Split(src)
return strings.Join(entries, " ")
}