From 99ff511117b2174821e32590cb8afd9d9e8aa94e Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Wed, 28 Nov 2018 18:11:15 +0100 Subject: [PATCH] fix: remote, sensor - list quiet --- cmd/remote/list.go | 6 +++++- pkg/remote/remote.go | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/remote/list.go b/cmd/remote/list.go index bc543b5..03c501c 100644 --- a/cmd/remote/list.go +++ b/cmd/remote/list.go @@ -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") } diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index d5629b7..2b3ddf8 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -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()