// Init initializes the command for running. func (c *BootstrapCommand) Init(args []string) error { if len(c.EnvConfig) == 0 { return cmdutil.RequiredError("model-config") } if c.InstanceId == "" { return cmdutil.RequiredError("instance-id") } if !names.IsValidUser(c.AdminUsername) { return errors.Errorf("%q is not a valid username", c.AdminUsername) } return c.AgentConf.CheckArgs(args) }
// Init initializes the command for running. func (a *UnitAgent) Init(args []string) error { if a.UnitName == "" { return cmdutil.RequiredError("unit-name") } if !names.IsValidUnit(a.UnitName) { return fmt.Errorf(`--unit-name option expects "<service>/<n>" argument`) } if err := a.AgentConf.CheckArgs(args); err != nil { return err } a.runner = worker.NewRunner(cmdutil.IsFatal, cmdutil.MoreImportant, worker.RestartDelay) if !a.logToStdErr { if err := a.ReadConfig(a.Tag().String()); err != nil { return err } agentConfig := a.CurrentConfig() // the writer in ctx.stderr gets set as the loggo writer in github.com/juju/cmd/logging.go a.ctx.Stderr = &lumberjack.Logger{ Filename: agent.LogFilename(agentConfig), MaxSize: 300, // megabytes MaxBackups: 2, } } return nil }
// CheckArgs reports whether the given args are valid for this agent. func (c *agentConf) CheckArgs(args []string) error { if c.dataDir == "" { return util.RequiredError("data-dir") } return cmd.CheckEmpty(args) }