diff --git a/cmd/describe.go b/cmd/describe.go index 5a6f4a8d49..f8beb99af2 100644 --- a/cmd/describe.go +++ b/cmd/describe.go @@ -89,8 +89,7 @@ func runDescribe(cmd *cobra.Command, args []string, newClient ClientFactory) (er } } - write(os.Stdout, info(details), cfg.Output) - return + return write(os.Stdout, info(details), cfg.Output) } // CLI Configuration (parameters) diff --git a/cmd/format.go b/cmd/format.go index f403c6e32d..bcad1bc925 100644 --- a/cmd/format.go +++ b/cmd/format.go @@ -24,25 +24,21 @@ type Formatter interface { URL(io.Writer) error } -// write to the output the output of the formatter's appropriate serilization function. -// the command to exit with value 2. -func write(out io.Writer, s Formatter, formatName string) { - var err error +// write the output using the formatter's appropriate serialization function, +// returning any errors to the caller for graceful handling. +func write(out io.Writer, s Formatter, formatName string) error { switch Format(formatName) { case Human: - err = s.Human(out) + return s.Human(out) case Plain: - err = s.Plain(out) + return s.Plain(out) case JSON: - err = s.JSON(out) + return s.JSON(out) case YAML: - err = s.YAML(out) + return s.YAML(out) case URL: - err = s.URL(out) + return s.URL(out) default: - err = fmt.Errorf("format not recognized: %v", formatName) - } - if err != nil { - panic(err) + return fmt.Errorf("format not recognized: %v", formatName) } } diff --git a/cmd/list.go b/cmd/list.go index 451d76e9d1..9fa5a11b38 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -68,7 +68,7 @@ Lists deployed functions. // Flags cmd.Flags().BoolP("all-namespaces", "A", false, "List functions in all namespaces. If set, the --namespace flag is ignored.") cmd.Flags().StringP("namespace", "n", defaultNamespace(fn.Function{}, false), "The namespace for which to list functions. ($FUNC_NAMESPACE)") - cmd.Flags().StringP("output", "o", "human", "Output format (human|plain|json|xml|yaml) ($FUNC_OUTPUT)") + cmd.Flags().StringP("output", "o", "human", "Output format (human|plain|json|yaml) ($FUNC_OUTPUT)") addVerboseFlag(cmd, cfg.Verbose) if err := cmd.RegisterFlagCompletionFunc("output", CompleteOutputFormatList); err != nil { @@ -119,9 +119,7 @@ To see functions here: return } - write(os.Stdout, listItems(items), cfg.Output) - - return + return write(os.Stdout, listItems(items), cfg.Output) } // CLI Configuration (parameters) diff --git a/cmd/version.go b/cmd/version.go index ca14a3824b..da82b99b58 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -95,8 +95,7 @@ func runVersion(cmd *cobra.Command, v Version) error { } v.MiddlewareVersions = latestMW - write(cmd.OutOrStdout(), v, output) - return nil + return write(cmd.OutOrStdout(), v, output) } // Version information populated on build. diff --git a/docs/reference/func_list.md b/docs/reference/func_list.md index f743e66334..522620a030 100644 --- a/docs/reference/func_list.md +++ b/docs/reference/func_list.md @@ -34,7 +34,7 @@ func list --all-namespaces --output json -A, --all-namespaces List functions in all namespaces. If set, the --namespace flag is ignored. -h, --help help for list -n, --namespace string The namespace for which to list functions. ($FUNC_NAMESPACE) (default "default") - -o, --output string Output format (human|plain|json|xml|yaml) ($FUNC_OUTPUT) (default "human") + -o, --output string Output format (human|plain|json|yaml) ($FUNC_OUTPUT) (default "human") -v, --verbose Print verbose logs ($FUNC_VERBOSE) ```