fix: remote, sensor - list quiet

This commit is contained in:
Markus Pesch 2018-11-28 18:11:15 +01:00
parent 617454f66b
commit 99ff511117
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 14 additions and 4 deletions

View File

@ -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")
}

View File

@ -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()