Skip to content
Open
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
3 changes: 1 addition & 2 deletions cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 9 additions & 13 deletions cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 2 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/func_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand Down
Loading