-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a pretty flag on some commands
This will simplify things on windows when no jq can not be installed that easy. Signed-off-by: Christian Ege <[email protected]>
- Loading branch information
Showing
3 changed files
with
25 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,32 +4,27 @@ Copyright © 2023 Christian Ege <[email protected]> | |
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/graugans/go-ovp8xx/pkg/ovp8xx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func getCommand(cmd *cobra.Command, args []string) error { | ||
|
||
pointers, err := cmd.Flags().GetStringSlice("pointer") | ||
if err != nil { | ||
return err | ||
} | ||
host, err := rootCmd.PersistentFlags().GetString("ip") | ||
var result ovp8xx.Config | ||
var err error | ||
helper, err := NewHelper(cmd) | ||
Check failure on line 14 in cmd/ovp8xx/cmd/get.go GitHub Actions / build
Check failure on line 14 in cmd/ovp8xx/cmd/get.go GitHub Actions / lint
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
o3r := ovp8xx.NewClient( | ||
ovp8xx.WithHost(host), | ||
ovp8xx.WithHost(helper.hostname()), | ||
) | ||
|
||
result, err := o3r.Get(pointers) | ||
if err != nil { | ||
if result, err = o3r.Get(helper.jsonPointers()); err != nil { | ||
return err | ||
} | ||
if err := helper.printJSONResult(result.String()); err != nil { | ||
return err | ||
} else { | ||
fmt.Printf("%s\n", result) | ||
} | ||
return nil | ||
} | ||
|
@@ -70,4 +65,5 @@ NOTE: This command only modifies temporary data, any changes will be lost after | |
func init() { | ||
rootCmd.AddCommand(getCmd) | ||
getCmd.Flags().StringSliceP("pointer", "p", []string{""}, "A JSON pointer to be queried") | ||
getCmd.Flags().Bool("pretty", false, "Pretty print the JSON received from the device") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,32 +4,27 @@ Copyright © 2023 Christian Ege <[email protected]> | |
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/graugans/go-ovp8xx/pkg/ovp8xx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func getSchemaCommand(cmd *cobra.Command, args []string) error { | ||
|
||
pointers, err := cmd.Flags().GetStringSlice("pointer") | ||
var result string | ||
var err error | ||
helper, err := NewHelper(cmd) | ||
Check failure on line 14 in cmd/ovp8xx/cmd/getSchema.go GitHub Actions / build
Check failure on line 14 in cmd/ovp8xx/cmd/getSchema.go GitHub Actions / lint
|
||
if err != nil { | ||
return err | ||
} | ||
o3r := ovp8xx.NewClient( | ||
ovp8xx.WithHost(helper.hostname()), | ||
) | ||
|
||
host, err := rootCmd.PersistentFlags().GetString("ip") | ||
if err != nil { | ||
if result, err = o3r.GetSchema(helper.jsonPointers()); err != nil { | ||
return err | ||
} | ||
|
||
o3r := ovp8xx.NewClient( | ||
ovp8xx.WithHost(host), | ||
) | ||
|
||
if result, err := o3r.GetSchema(pointers); err != nil { | ||
if err := helper.printJSONResult(result); err != nil { | ||
return err | ||
} else { | ||
fmt.Printf("%s\n", result) | ||
} | ||
return nil | ||
} | ||
|
@@ -89,4 +84,5 @@ When no query is provided the complete schema is returend. | |
func init() { | ||
rootCmd.AddCommand(getSchemaCmd) | ||
getSchemaCmd.Flags().StringSliceP("pointer", "p", []string{""}, "A JSON pointer to be queried. This can be used multiple times") | ||
getSchemaCmd.Flags().Bool("pretty", false, "Pretty print the JSON received from the device") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,26 @@ Copyright © 2023 Christian Ege <[email protected]> | |
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/graugans/go-ovp8xx/pkg/ovp8xx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func getInitCommand(cmd *cobra.Command, args []string) error { | ||
|
||
host, err := rootCmd.PersistentFlags().GetString("ip") | ||
var result ovp8xx.Config | ||
var err error | ||
helper, err := NewHelper(cmd) | ||
Check failure on line 14 in cmd/ovp8xx/cmd/getinit.go GitHub Actions / build
Check failure on line 14 in cmd/ovp8xx/cmd/getinit.go GitHub Actions / lint
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
o3r := ovp8xx.NewClient( | ||
ovp8xx.WithHost(host), | ||
ovp8xx.WithHost(helper.hostname()), | ||
) | ||
|
||
if result, err := o3r.GetInit(); err != nil { | ||
if result, err = o3r.GetInit(); err != nil { | ||
return err | ||
} else { | ||
fmt.Printf("%s\n", result) | ||
} | ||
helper.printJSONResult(result.String()) | ||
return nil | ||
} | ||
|
||
|
@@ -42,4 +40,5 @@ longer useable when the expectation from the safed configuration is no longer me | |
|
||
func init() { | ||
rootCmd.AddCommand(getInitCmd) | ||
getInitCmd.Flags().Bool("pretty", false, "Pretty print the JSON received from the device") | ||
} |