cli: differentiate normal output vs info

This commit is contained in:
Michael Schurter
2018-03-30 11:42:11 -07:00
parent 55b98ee299
commit 7ff790bc7d
6 changed files with 28 additions and 17 deletions

View File

@@ -478,9 +478,9 @@ func (c *Command) Run(args []string) int {
// Log config files
if len(config.Files) > 0 {
c.Ui.Info(fmt.Sprintf("Loaded configuration from %s", strings.Join(config.Files, ", ")))
c.Ui.Output(fmt.Sprintf("Loaded configuration from %s", strings.Join(config.Files, ", ")))
} else {
c.Ui.Info("No configuration files loaded")
c.Ui.Output("No configuration files loaded")
}
// Initialize the telemetry
@@ -529,7 +529,7 @@ func (c *Command) Run(args []string) int {
padding := 18
c.Ui.Output("Nomad agent configuration:\n")
for _, k := range infoKeys {
c.Ui.Info(fmt.Sprintf(
c.Ui.Output(fmt.Sprintf(
"%s%s: %s",
strings.Repeat(" ", padding-len(k)),
strings.Title(k),
@@ -831,7 +831,7 @@ func (c *Command) startupJoin(config *Config) error {
return err
}
c.Ui.Info(fmt.Sprintf("Join completed. Synced with %d initial agents", n))
c.Ui.Output(fmt.Sprintf("Join completed. Synced with %d initial agents", n))
return nil
}

View File

@@ -48,7 +48,7 @@ func (c *DeprecatedCommand) warn() {
// Commands returns the mapping of CLI commands for Nomad. The meta
// parameter lets you set meta options for all commands.
func Commands(metaPtr *Meta) map[string]cli.CommandFactory {
func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory {
if metaPtr == nil {
metaPtr = new(Meta)
}
@@ -156,7 +156,7 @@ func Commands(metaPtr *Meta) map[string]cli.CommandFactory {
"agent": func() (cli.Command, error) {
return &agent.Command{
Version: version.GetVersion(),
Ui: meta.Ui,
Ui: agentUi,
ShutdownCh: make(chan struct{}),
}, nil
},

View File

@@ -286,6 +286,8 @@ func (c *NodeDrainCommand) Run(args []string) int {
outCh := client.Nodes().MonitorDrain(context.Background(), node.ID, meta.LastIndex, ignoreSystem)
for msg := range outCh {
switch msg.Level {
case api.MonitorMsgLevelInfo:
c.Ui.Info(fmt.Sprintf("%s: %s", formatTime(time.Now()), msg))
case api.MonitorMsgLevelWarn:
c.Ui.Warn(fmt.Sprintf("%s: %s", formatTime(time.Now()), msg))
case api.MonitorMsgLevelError:

View File

@@ -114,7 +114,7 @@ func (c *OperatorKeyringCommand) Run(args []string) int {
}
if listKeys {
c.Ui.Info("Gathering installed encryption keys...")
c.Ui.Output("Gathering installed encryption keys...")
r, err := client.Agent().ListKeys()
if err != nil {
c.Ui.Error(fmt.Sprintf("error: %s", err))
@@ -125,7 +125,7 @@ func (c *OperatorKeyringCommand) Run(args []string) int {
}
if installKey != "" {
c.Ui.Info("Installing new gossip encryption key...")
c.Ui.Output("Installing new gossip encryption key...")
_, err := client.Agent().InstallKey(installKey)
if err != nil {
c.Ui.Error(fmt.Sprintf("error: %s", err))
@@ -135,7 +135,7 @@ func (c *OperatorKeyringCommand) Run(args []string) int {
}
if useKey != "" {
c.Ui.Info("Changing primary gossip encryption key...")
c.Ui.Output("Changing primary gossip encryption key...")
_, err := client.Agent().UseKey(useKey)
if err != nil {
c.Ui.Error(fmt.Sprintf("error: %s", err))
@@ -145,7 +145,7 @@ func (c *OperatorKeyringCommand) Run(args []string) int {
}
if removeKey != "" {
c.Ui.Info("Removing gossip encryption key...")
c.Ui.Output("Removing gossip encryption key...")
_, err := client.Agent().RemoveKey(removeKey)
if err != nil {
c.Ui.Error(fmt.Sprintf("error: %s", err))