diff --git a/cmd/list.go b/cmd/list.go index efbcbbad..f71c71b3 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -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", @@ -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, diff --git a/pkg/output/main.go b/pkg/output/main.go index 756bd69c..7a3115e3 100644 --- a/pkg/output/main.go +++ b/pkg/output/main.go @@ -26,6 +26,7 @@ type Options struct { JSON bool Pretty bool Debug bool + Error string } // Result . @@ -125,6 +126,9 @@ func RenderOutput(data Table, opts Options) { RenderJSON(returnedData, opts) } else { // otherwise render a table + if opts.Error != "" { + os.Stdout.WriteString(opts.Error) + } table := tablewriter.NewWriter(os.Stdout) opts.Header = !opts.Header if opts.Header {