github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/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  	"github.com/juju/charmstore"
    10  	"github.com/juju/cmd"
    11  	"launchpad.net/gnuflag"
    12  )
    13  
    14  // ConfigCommand defines a command which requires a YAML config file.
    15  type ConfigCommand struct {
    16  	cmd.CommandBase
    17  	ConfigPath string
    18  	Config     *charmstore.Config
    19  }
    20  
    21  type CharmdConfig struct {
    22  	MongoUrl string `yaml:"mongo-url"`
    23  }
    24  
    25  func (c *ConfigCommand) SetFlags(f *gnuflag.FlagSet) {
    26  	f.StringVar(&c.ConfigPath, "config", "", "charmd configuration file")
    27  }
    28  
    29  func (c *ConfigCommand) Init(args []string) error {
    30  	if c.ConfigPath == "" {
    31  		return fmt.Errorf("--config is required")
    32  	}
    33  	return nil
    34  }
    35  
    36  func (c *ConfigCommand) ReadConfig(ctx *cmd.Context) (err error) {
    37  	c.Config, err = charmstore.ReadConfig(ctx.AbsPath(c.ConfigPath))
    38  	return err
    39  }