Ejemplo n.º 1
0
func getConfig(c *cli.Context) (*manager.Config, string, error) {
	var reader io.Reader
	configFile := ""
	if !c.GlobalIsSet("config") {
		logrus.Debugf("no configuration was specified, starting with default.")
	} else if c.GlobalString("config") == "-" {
		logrus.Debugf("reading configuration from stdin")
		reader = bufio.NewReader(os.Stdin)
	} else {
		f, err := os.Open(c.GlobalString("config"))
		if err != nil {
			return nil, "", errored.Errorf("failed to open config file. Error: %v", err)
		}
		defer func() { f.Close() }()
		logrus.Debugf("reading configuration from file: %q", c.GlobalString("config"))
		reader = bufio.NewReader(f)
		configFile = c.GlobalString("config")
	}
	config := manager.DefaultConfig()
	if reader != nil {
		if _, err := config.MergeFromReader(reader); err != nil {
			return nil, "", errored.Errorf("failed to merge configuration. Error: %v", err)
		}
	}
	return config, configFile, nil
}
Ejemplo n.º 2
0
package main

import (
	"github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"github.com/contiv/cluster/management/src/clusterm/manager"
	"github.com/contiv/errored"
)

var (
	clustermFlags = []cli.Flag{
		cli.StringFlag{
			Name:  "url, u",
			Value: manager.DefaultConfig().Manager.Addr,
			Usage: "cluster manager's REST service url",
		},
	}

	extraVarsFlag = cli.StringFlag{
		Name:  "extra-vars, e",
		Value: "",
		Usage: "extra vars for ansible configuration. This should be a quoted json string.",
	}

	jsonFlag = cli.BoolFlag{
		Name:  "json, j",
		Usage: "print command output in JSON",
	}

	getFlags = []cli.Flag{
		jsonFlag,