launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/cmd/charm-admin/config.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package main 5 6 import ( 7 "fmt" 8 9 "launchpad.net/gnuflag" 10 11 "launchpad.net/juju-core/cmd" 12 "launchpad.net/juju-core/store" 13 ) 14 15 // ConfigCommand defines a command which requires a YAML config file. 16 type ConfigCommand struct { 17 cmd.CommandBase 18 ConfigPath string 19 Config *store.Config 20 } 21 22 type CharmdConfig struct { 23 MongoUrl string `yaml:"mongo-url"` 24 } 25 26 func (c *ConfigCommand) SetFlags(f *gnuflag.FlagSet) { 27 f.StringVar(&c.ConfigPath, "config", "", "charmd configuration file") 28 } 29 30 func (c *ConfigCommand) Init(args []string) error { 31 if c.ConfigPath == "" { 32 return fmt.Errorf("--config is required") 33 } 34 return nil 35 } 36 37 func (c *ConfigCommand) ReadConfig(ctx *cmd.Context) (err error) { 38 c.Config, err = store.ReadConfig(ctx.AbsPath(c.ConfigPath)) 39 return err 40 }