// parseFlags parses and validates the command line arguments. func (cmd *Command) parseFlags(args []string) (*Config, string, error) { fs := flag.NewFlagSet("", flag.ContinueOnError) configPath := fs.String("config", "", "") fs.SetOutput(cmd.Stderr) fs.Usage = cmd.printUsage if err := fs.Parse(args); err != nil { return nil, "", err } // Parse configuration file from disk. if *configPath == "" { return nil, "", fmt.Errorf("config required") } // Parse config. config := Config{ Meta: meta.NewConfig(), Data: tsdb.NewConfig(), } if _, err := toml.DecodeFile(*configPath, &config); err != nil { return nil, "", err } // Require output path. path := fs.Arg(0) if path == "" { return nil, "", fmt.Errorf("snapshot path required") } return &config, path, nil }
// NewConfig returns an instance of Config with reasonable defaults. func NewConfig() *Config { c := &Config{} c.Meta = meta.NewConfig() c.Data = tsdb.NewConfig() c.Cluster = cluster.NewConfig() c.Precreator = precreator.NewConfig() c.Admin = admin.NewConfig() c.HTTPD = httpd.NewConfig() c.Collectd = collectd.NewConfig() c.OpenTSDB = opentsdb.NewConfig() c.Graphites = append(c.Graphites, graphite.NewConfig()) c.Monitoring = monitor.NewConfig() c.ContinuousQuery = continuous_querier.NewConfig() c.Retention = retention.NewConfig() c.HintedHandoff = hh.NewConfig() return c }