Skip to content

Commit

Permalink
Change: Updates the output from an Error to Stderr when listing v…
Browse files Browse the repository at this point in the history
…ariables where none are set (#298)
  • Loading branch information
CGoodwin90 committed Oct 30, 2023
1 parent 31c24bc commit f5b467e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@ var listVariablesCmd = &cobra.Command{
}
data = append(data, env)
}
if len(data) == 0 {
if cmdProjectEnvironment != "" {
return fmt.Errorf("There are no variables for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName)
} else {
return fmt.Errorf("There are no variables for project '%s'", cmdProjectName)
}
}
header := []string{
"ID",
"Project",
Expand All @@ -309,6 +302,13 @@ var listVariablesCmd = &cobra.Command{
if reveal {
header = append(header, "Value")
}
if len(data) == 0 {
if cmdProjectEnvironment != "" {
outputOptions.Error = fmt.Sprintf("There are no variables for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName)
} else {
outputOptions.Error = fmt.Sprintf("There are no variables for project '%s'\n", cmdProjectName)
}
}
output.RenderOutput(output.Table{
Header: header,
Data: data,
Expand Down
4 changes: 4 additions & 0 deletions pkg/output/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Options struct {
JSON bool
Pretty bool
Debug bool
Error string
}

// Result .
Expand Down Expand Up @@ -125,6 +126,9 @@ func RenderOutput(data Table, opts Options) {
RenderJSON(returnedData, opts)
} else {
// otherwise render a table
if opts.Error != "" {
os.Stderr.WriteString(opts.Error)
}
table := tablewriter.NewWriter(os.Stdout)
opts.Header = !opts.Header
if opts.Header {
Expand Down

0 comments on commit f5b467e

Please sign in to comment.