Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ The default value for `no_color` is `false`
#### default_output

Sets the default output format for commands. Currently, the application
supports two output formats `human` and `json`. Use this configuration to
define the default output format for all commands.
supports three output formats `human`,`json` and `yaml`. Use this
configuration to define the default output format for all commands.

This setting can be override for any command using `--output <format>`

Expand Down
35 changes: 3 additions & 32 deletions internal/handlers/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,37 +128,10 @@ func NewCommand(c *CommandRunner) *cobra.Command {
checkError(err, c.Runtime)

if c.Runtime.Config.TerminalDefaultOutput == "json" {
if resp.Json != nil {
terminal.Display(string(resp.Json))
} else {
terminal.Display(resp.String())
}
terminal.Display("")

} else if c.Runtime.Config.TerminalDefaultOutput == "url" && resp.Url != "" {
profile, _ := c.Runtime.Config.ActiveProfile()

var u string

if profile.UseTLS {
u = "https://"
} else {
u = "http://"
}

u += profile.Host

if profile.Port != 0 {
u += fmt.Sprintf(":%v", profile.Port)
}

if strings.HasPrefix(resp.Url, "/") {
u += resp.Url
} else {
u += fmt.Sprintf("/%s", resp.Url)
}
checkError(terminal.DisplayJson(resp.Object), c.Runtime)

terminal.Display(u)
} else if c.Runtime.Config.TerminalDefaultOutput == "yaml" {
checkError(terminal.DisplayYaml(resp.Object), c.Runtime)

} else if len(resp.Lines) > 0 {
if c.Runtime.Config.TerminalPager {
Expand All @@ -170,8 +143,6 @@ func NewCommand(c *CommandRunner) *cobra.Command {
} else {
if resp.Text != "" {
terminal.Display(resp.String())
} else if resp.Json != nil {
terminal.Display(string(resp.Json))
} else {
terminal.Display("unable to display response")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/runners/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *AccountRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(accounts),
WithObject(accounts),
), nil
}

Expand Down Expand Up @@ -75,6 +75,6 @@ func (r *AccountRunner) Describe(in Request) (*Response, error) {

return NewResponse(
"",
WithJson(account),
WithObject(account),
), nil
}
2 changes: 0 additions & 2 deletions internal/runners/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func TestGet(t *testing.T) {
assert.NotNil(t, res)
assert.Empty(t, res.Text)
assert.NotEmpty(t, res.Lines)
assert.NotEmpty(t, res.Json)
}

func TestDescribe(t *testing.T) {
Expand All @@ -47,5 +46,4 @@ func TestDescribe(t *testing.T) {
assert.NotNil(t, res)
assert.Empty(t, res.Text)
assert.NotEmpty(t, res.Lines)
assert.NotEmpty(t, res.Json)
}
2 changes: 1 addition & 1 deletion internal/runners/adapter_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (r *AdapterModelRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(res),
WithObject(res),
), nil

}
Expand Down
6 changes: 3 additions & 3 deletions internal/runners/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *AdapterRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(adapters),
WithObject(adapters),
), nil
}

Expand All @@ -77,7 +77,7 @@ func (r *AdapterRunner) Describe(in Request) (*Response, error) {

return NewResponse(
string(b),
WithJson(res),
WithObject(res),
), nil
}

Expand Down Expand Up @@ -362,7 +362,7 @@ func (r *AdapterRunner) Inspect(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(adapters),
WithObject(adapters),
), nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/runners/analytic_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *AnalyticTemplateRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(templates),
WithObject(templates),
), nil

}
Expand All @@ -75,7 +75,7 @@ func (r *AnalyticTemplateRunner) Describe(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Name: %s", template.Name),
WithJson(template),
WithObject(template),
), nil
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (r *AnalyticTemplateRunner) Create(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Successfully created analytic template `%s`", name),
WithJson(res),
WithObject(res),
), nil
}

Expand Down
10 changes: 5 additions & 5 deletions internal/runners/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *ApiRunner) Get(in Request) (*Response, error) {

return NewResponse(
res,
WithJson(jsonRes),
WithObject(jsonRes),
), nil
}

Expand All @@ -103,7 +103,7 @@ func (r *ApiRunner) Delete(in Request) (*Response, error) {

return NewResponse(
res,
WithJson(jsonRes),
WithObject(jsonRes),
), nil
}

Expand All @@ -130,7 +130,7 @@ func (r *ApiRunner) Post(in Request) (*Response, error) {

return NewResponse(
res,
WithJson(jsonRes),
WithObject(jsonRes),
), nil
}

Expand All @@ -157,7 +157,7 @@ func (r *ApiRunner) Put(in Request) (*Response, error) {

return NewResponse(
res,
WithJson(jsonRes),
WithObject(jsonRes),
), nil
}

Expand All @@ -184,6 +184,6 @@ func (r *ApiRunner) Patch(in Request) (*Response, error) {

return NewResponse(
res,
WithJson(jsonRes),
WithObject(jsonRes),
), nil
}
6 changes: 3 additions & 3 deletions internal/runners/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r *ApplicationRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(res),
WithObject(res),
), nil

}
Expand All @@ -71,7 +71,7 @@ func (r *ApplicationRunner) Describe(in Request) (*Response, error) {

return NewResponse(
string(b),
WithJson(res),
WithObject(res),
), nil
}

Expand Down Expand Up @@ -137,6 +137,6 @@ func (r *ApplicationRunner) Inspect(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(res),
WithObject(res),
), nil
}
6 changes: 3 additions & 3 deletions internal/runners/automations.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *AutomationRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(automations),
WithObject(automations),
), nil
}

Expand All @@ -75,7 +75,7 @@ func (r *AutomationRunner) Describe(in Request) (*Response, error) {

return NewResponse(
"",
WithJson(res),
WithObject(res),
), nil
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (r *AutomationRunner) Create(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Successfully created automation `%s`", res.Name),
WithJson(res),
WithObject(res),
), nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/runners/command_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *CommandTemplateRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(templates),
WithObject(templates),
), nil

}
Expand All @@ -79,7 +79,7 @@ func (r *CommandTemplateRunner) Describe(in Request) (*Response, error) {

return NewResponse(
strings.Join(output, "\n"),
WithJson(res),
WithObject(res),
), nil
}

Expand All @@ -99,7 +99,7 @@ func (r *CommandTemplateRunner) Create(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Successfully created command template `%s` (%s)", res.Name, res.Id),
WithJson(res),
WithObject(res),
), nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/runners/config_parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r *ConfigurationParserRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(devices),
WithObject(devices),
), nil

}
Expand All @@ -63,7 +63,7 @@ func (r *ConfigurationParserRunner) Describe(in Request) (*Response, error) {
return NewResponse(
fmt.Sprintf("Name: %s", res.Name),
WithUrl(fmt.Sprintf("/configuration_manager/#/devices/%s", res.Name)),
WithJson(res),
WithObject(res),
), nil
*/
}
5 changes: 2 additions & 3 deletions internal/runners/devicegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *DeviceGroupRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(devices),
WithObject(devices),
), nil

}
Expand All @@ -61,7 +61,6 @@ func (r *DeviceGroupRunner) Describe(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Name: %s", res.Name),
WithUrl(fmt.Sprintf("/configuration_manager/#/devices/%s", res.Name)),
WithJson(res),
WithObject(res),
), nil
}
5 changes: 2 additions & 3 deletions internal/runners/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *DeviceRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(devices),
WithObject(devices),
), nil

}
Expand All @@ -61,7 +61,6 @@ func (r *DeviceRunner) Describe(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Name: %s", res.Name),
WithUrl(fmt.Sprintf("/configuration_manager/#/devices/%s", res.Name)),
WithJson(res),
WithObject(res),
), nil
}
4 changes: 2 additions & 2 deletions internal/runners/gctrees.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *GoldenConfigRunner) Get(in Request) (*Response, error) {

return NewResponse(
strings.Join(display, "\n"),
WithJson(trees),
WithObject(trees),
), nil
}

Expand All @@ -70,7 +70,7 @@ func (r *GoldenConfigRunner) Create(in Request) (*Response, error) {

return NewResponse(
"Successfully create new golden configuration",
WithJson(gc),
WithObject(gc),
), nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/runners/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *GroupRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(groups),
WithObject(groups),
), nil

}
Expand Down Expand Up @@ -81,7 +81,7 @@ func (r *GroupRunner) Describe(in Request) (*Response, error) {

return NewResponse(
"",
WithJson(grp),
WithObject(grp),
), nil
}

Expand All @@ -104,7 +104,7 @@ func (r *GroupRunner) Create(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Successfully created group `%s`", in.Args[0]),
WithJson(res),
WithObject(res),
), nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/runners/integration_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *IntegrationModelRunner) Get(in Request) (*Response, error) {
return NewResponse(
"",
WithTable(display),
WithJson(res),
WithObject(res),
), nil

}
Expand All @@ -62,7 +62,7 @@ func (r *IntegrationModelRunner) Describe(in Request) (*Response, error) {

return NewResponse(
fmt.Sprintf("Name: %s", res.Model),
WithJson(res),
WithObject(res),
), nil
}

Expand Down
Loading
Loading