Skip to content

Commit

Permalink
updated version flag to internal/flags (hauler-dev#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbradys authored Dec 4, 2024
1 parent 01faf39 commit f5e3b38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/hauler/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func addVersion(parent *cobra.Command, ro *flags.CliRootOpts) {
var json bool
o := &flags.VersionOpts{}

cmd := &cobra.Command{
Use: "version",
Expand All @@ -23,7 +23,7 @@ func addVersion(parent *cobra.Command, ro *flags.CliRootOpts) {
v.FontName = "starwars"
cmd.SetOut(cmd.OutOrStdout())

if json {
if o.JSON {
out, err := v.JSONString()
if err != nil {
return fmt.Errorf("unable to generate JSON from version info: %w", err)
Expand All @@ -35,7 +35,7 @@ func addVersion(parent *cobra.Command, ro *flags.CliRootOpts) {
return nil
},
}
cmd.Flags().BoolVar(&json, "json", false, "toggle output in JSON")
o.AddFlags(cmd)

parent.AddCommand(cmd)
}
12 changes: 12 additions & 0 deletions internal/flags/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package flags

import "github.com/spf13/cobra"

type VersionOpts struct {
JSON bool
}

func (o *VersionOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()
f.BoolVar(&o.JSON, "json", false, "Set the output format to JSON")
}

0 comments on commit f5e3b38

Please sign in to comment.