diff --git a/command/alloc_status.go b/command/alloc_status.go index 21cc39e6a..ff9af16a3 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -44,11 +44,11 @@ Alloc Status Options: -verbose Show full information. - -format - Display specified format, "json" or "template". + -json + Display information with json format. -t - Sets the template with golang templates format. + Set golang templates format and display information with it. ` return strings.TrimSpace(helpText) @@ -59,15 +59,15 @@ func (c *AllocStatusCommand) Synopsis() string { } func (c *AllocStatusCommand) Run(args []string) int { - var short, displayStats, verbose bool - var format, tmpl string + var short, displayStats, verbose, json bool + var tmpl string flags := c.Meta.FlagSet("alloc-status", FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } flags.BoolVar(&short, "short", false, "") flags.BoolVar(&verbose, "verbose", false, "") flags.BoolVar(&displayStats, "stats", false, "") - flags.StringVar(&format, "format", "default", "") + flags.BoolVar(&json, "json", false, "") flags.StringVar(&tmpl, "t", "", "") if err := flags.Parse(args); err != nil { @@ -140,7 +140,13 @@ func (c *AllocStatusCommand) Run(args []string) int { } // If output format is specified, format and output the data - if format != "default" { + var format string + if json { + format = "json" + } else if len(tmpl) > 0 { + format = "template" + } + if len(format) > 0 { f, err := DataFormat(format, tmpl) if err != nil { c.Ui.Error(fmt.Sprintf("Error getting formatter: %s", err)) diff --git a/command/data_format.go b/command/data_format.go index 492562941..c11887b9b 100644 --- a/command/data_format.go +++ b/command/data_format.go @@ -18,6 +18,9 @@ type DataFormatter interface { func DataFormat(format, tmpl string) (DataFormatter, error) { switch format { case "json": + if len(tmpl) > 0 { + return nil, fmt.Errorf("json format does not support template option.") + } return &JSONFormat{}, nil case "template": return &TemplateFormat{tmpl}, nil diff --git a/command/eval_status.go b/command/eval_status.go index ff8becd66..88799d3fd 100644 --- a/command/eval_status.go +++ b/command/eval_status.go @@ -32,11 +32,11 @@ Eval Status Options: -verbose Show full information. - -format - Display specified format, "json" or "template". + -json + Display information with json format. -t - Sets the template with golang templates format. + Set golang templates format and display information with it. ` return strings.TrimSpace(helpText) @@ -47,14 +47,14 @@ func (c *EvalStatusCommand) Synopsis() string { } func (c *EvalStatusCommand) Run(args []string) int { - var monitor, verbose bool - var format, tmpl string + var monitor, verbose, json bool + var tmpl string flags := c.Meta.FlagSet("eval-status", FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } flags.BoolVar(&monitor, "monitor", false, "") flags.BoolVar(&verbose, "verbose", false, "") - flags.StringVar(&format, "format", "default", "") + flags.BoolVar(&json, "json", false, "") flags.StringVar(&tmpl, "t", "", "") if err := flags.Parse(args); err != nil { @@ -134,7 +134,13 @@ func (c *EvalStatusCommand) Run(args []string) int { } // If output format is specified, format and output the data - if format != "default" { + var format string + if json { + format = "json" + } else if len(tmpl) > 0 { + format = "template" + } + if len(format) > 0 { f, err := DataFormat(format, tmpl) if err != nil { c.Ui.Error(fmt.Sprintf("Error getting formatter: %s", err)) diff --git a/command/node_status.go b/command/node_status.go index 274bc8967..13d4a154c 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -30,7 +30,7 @@ type NodeStatusCommand struct { list_allocs bool self bool stats bool - format string + json bool tmpl string } @@ -69,11 +69,11 @@ Node Status Options: -verbose Display full information. - -format - Display specified format, "json" or "template". + -json + Display information with json format. -t - Sets the template with golang templates format. + Set golang templates format and display information with it. ` return strings.TrimSpace(helpText) } @@ -91,7 +91,7 @@ func (c *NodeStatusCommand) Run(args []string) int { flags.BoolVar(&c.list_allocs, "allocs", false, "") flags.BoolVar(&c.self, "self", false, "") flags.BoolVar(&c.stats, "stats", false, "") - flags.StringVar(&c.format, "format", "default", "") + flags.BoolVar(&c.json, "json", false, "") flags.StringVar(&c.tmpl, "t", "", "") if err := flags.Parse(args); err != nil { @@ -227,8 +227,14 @@ func (c *NodeStatusCommand) Run(args []string) int { } // If output format is specified, format and output the data - if c.format != "default" { - f, err := DataFormat(c.format, c.tmpl) + var format string + if c.json { + format = "json" + } else if len(c.tmpl) > 0 { + format = "template" + } + if len(format) > 0 { + f, err := DataFormat(format, c.tmpl) if err != nil { c.Ui.Error(fmt.Sprintf("Error getting formatter: %s", err)) return 1 diff --git a/command/status.go b/command/status.go index a11ad6e6b..dcca9c1bd 100644 --- a/command/status.go +++ b/command/status.go @@ -46,12 +46,6 @@ Status Options: -verbose Display full information. - - -format - Display specified format, "json" or "template". - - -t - Sets the template with golang templates format. ` return strings.TrimSpace(helpText) } @@ -62,15 +56,12 @@ func (c *StatusCommand) Synopsis() string { func (c *StatusCommand) Run(args []string) int { var short bool - var format, tmpl string flags := c.Meta.FlagSet("status", FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } flags.BoolVar(&short, "short", false, "") flags.BoolVar(&c.showEvals, "evals", false, "") flags.BoolVar(&c.verbose, "verbose", false, "") - flags.StringVar(&format, "format", "default", "") - flags.StringVar(&tmpl, "t", "", "") if err := flags.Parse(args); err != nil { return 1 @@ -154,23 +145,6 @@ func (c *StatusCommand) Run(args []string) int { return 1 } - // If output format is specified, format and output the data - if format != "default" { - f, err := DataFormat(format, tmpl) - if err != nil { - c.Ui.Error(fmt.Sprintf("Error getting formatter: %s", err)) - return 1 - } - - out, err := f.TransformData(job) - if err != nil { - c.Ui.Error(fmt.Sprintf("Error transform the data: %s", err)) - return 1 - } - c.Ui.Output(out) - return 0 - } - // Check if it is periodic sJob, err := convertApiJob(job) if err != nil {