Skip to content

Commit

Permalink
fix: add the missing file and any linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Ege <[email protected]>
  • Loading branch information
graugans committed Dec 6, 2023
1 parent ac6aeec commit 7bdfc1b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/ovp8xx/cmd/getinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func getInitCommand(cmd *cobra.Command, args []string) error {
if result, err = o3r.GetInit(); err != nil {
return err
}
helper.printJSONResult(result.String())
if err = helper.printJSONResult(result.String()); err != nil {
return err
}
return nil
}

Expand Down
56 changes: 56 additions & 0 deletions cmd/ovp8xx/cmd/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd

import (
"encoding/json"
"errors"
"fmt"

"github.com/spf13/cobra"
)

type helperConfig struct {
pretty bool
host string
pointers []string
}

func (c *helperConfig) printJSONResult(data string) error {
var message string = data
if c.pretty {
var js json.RawMessage
if err := json.Unmarshal([]byte(data), &js); err != nil {
return errors.New("malformed json")
}
jsonIndented, err := json.MarshalIndent(js, "", " ")
if err != nil {
return err
}
message = string(jsonIndented)
}
fmt.Print(message)
return nil
}

func (c *helperConfig) hostname() string {
return c.host
}

func (c *helperConfig) jsonPointers() []string {
return c.pointers
}

func NewHelper(cmd *cobra.Command) (helperConfig, error) {
var conf = helperConfig{}
var err error
conf.pretty, err = cmd.Flags().GetBool("pretty")
if err != nil {
return conf, err
}
conf.host, err = rootCmd.PersistentFlags().GetString("ip")
if err != nil {
return conf, err
}
// Pointers can be empty
conf.pointers, _ = cmd.Flags().GetStringSlice("pointer")
return conf, nil
}

0 comments on commit 7bdfc1b

Please sign in to comment.