fix: remote, sensor - list quiet
This commit is contained in:
parent
617454f66b
commit
99ff511117
@ -8,12 +8,14 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var quiet bool
|
||||
|
||||
var listRemoteCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List Remove Servers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := remote.Print(os.Stdout, configDir); err != nil {
|
||||
if err := remote.Print(os.Stdout, configDir, quiet); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
@ -21,4 +23,6 @@ var listRemoteCmd = &cobra.Command{
|
||||
|
||||
func init() {
|
||||
remoteCmd.AddCommand(listRemoteCmd)
|
||||
|
||||
listRemoteCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "List only sensor id's")
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func Disable(remoteName string, configDir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Print(w io.Writer, configDir string) error {
|
||||
func Print(w io.Writer, configDir string, quiet bool) error {
|
||||
|
||||
configuration, err := config.Read(configDir)
|
||||
if err != nil {
|
||||
@ -97,10 +97,16 @@ func Print(w io.Writer, configDir string) error {
|
||||
|
||||
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
|
||||
|
||||
fmt.Fprint(tw, "name\taddress\tenabled\tregistered\n")
|
||||
if !quiet {
|
||||
fmt.Fprint(tw, "name\taddress\tenabled\tregistered\n")
|
||||
}
|
||||
|
||||
for _, remote := range configuration.Remotes {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n", remote.Name, remote.Address, remote.Enabled, remote.Registered)
|
||||
if quiet {
|
||||
fmt.Fprintf(tw, "%v\n", remote.Name)
|
||||
} else {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n", remote.Name, remote.Address, remote.Enabled, remote.Registered)
|
||||
}
|
||||
}
|
||||
|
||||
tw.Flush()
|
||||
|
Loading…
Reference in New Issue
Block a user