Skip to content

Commit

Permalink
Unhide release inspect command (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin authored Jan 17, 2025
1 parent db7b825 commit ec00ac7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
26 changes: 18 additions & 8 deletions cli/cmd/release_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@ import (

func (r *runners) InitReleaseInspect(parent *cobra.Command) {
cmd := &cobra.Command{
Use: "inspect SEQUENCE",
Short: "Print the YAML config for a release",
Long: "Print the YAML config for a release",
Use: "inspect RELEASE_SEQUENCE",
Short: "Long: information about a release",
Long: `Show information about the specified application release.
This command displays detailed information about a specific release of an application.
The output can be customized using the --output flag to display results in
either table or JSON format.
`,
Example: ` # Display information about a release
replicated release inspect 123
# Display information about a release in JSON format
replicated release inspect 123 --output json`,
Args: cobra.ExactArgs(1),
}
cmd.Hidden = true // Not supported in KOTS
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")
parent.AddCommand(cmd)

cmd.RunE = r.releaseInspect
}

Expand All @@ -26,9 +39,6 @@ func (r *runners) releaseInspect(_ *cobra.Command, args []string) error {
return errors.New("no app specified")
}

if len(args) != 1 {
return errors.New("release sequence is required")
}
seq, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return fmt.Errorf("Failed to parse sequence argument %s", args[0])
Expand All @@ -42,5 +52,5 @@ func (r *runners) releaseInspect(_ *cobra.Command, args []string) error {
return err
}

return print.Release(r.w, release)
return print.Release(r.outputFormat, r.w, release)
}
15 changes: 12 additions & 3 deletions cli/print/release.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package print

import (
"encoding/json"
"fmt"
"text/tabwriter"
"text/template"

Expand All @@ -21,9 +23,16 @@ CONFIG:

var releaseTmpl = template.Must(template.New("Release").Funcs(funcs).Parse(releaseTmplSrc))

func Release(w *tabwriter.Writer, release *types.AppRelease) error {
if err := releaseTmpl.Execute(w, release); err != nil {
return err
func Release(outputFormat string, w *tabwriter.Writer, release *types.AppRelease) error {
if outputFormat == "table" {
if err := releaseTmpl.Execute(w, release); err != nil {
return err
}
} else if outputFormat == "json" {
cAsByte, _ := json.MarshalIndent(release, "", " ")
if _, err := fmt.Fprintln(w, string(cAsByte)); err != nil {
return err
}
}
return w.Flush()
}

0 comments on commit ec00ac7

Please sign in to comment.