feat: list configured loggers

This commit is contained in:
Markus Pesch 2019-03-04 21:19:33 +01:00
parent 88f6116a41
commit 3d54401011
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 55 additions and 0 deletions

40
cmd/logger/list.go Normal file
View File

@ -0,0 +1,40 @@
package logger
import (
"log"
"os"
"git.cryptic.systems/fh-trier/go-flucky/pkg/cli"
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
"github.com/spf13/cobra"
)
var quiet bool
var listLoggerCmd = &cobra.Command{
Use: "ls",
Short: "List internal Loggers",
Aliases: []string{"list"},
Example: "flucky logger ls",
Run: func(cmd *cobra.Command, args []string) {
// read configuration
fc, err := config.Read(cfg)
if err != nil {
log.Fatalln(err)
}
// print all configured remote addresses on stdout
cli.PrintLoggers(fc, os.Stdout)
// save new configuration
err = config.Write(fc, cfg)
if err != nil {
log.Fatalln(err)
}
},
}
func init() {
loggerCmd.AddCommand(listLoggerCmd)
}

View File

@ -5,6 +5,8 @@ import (
"io" "io"
"text/tabwriter" "text/tabwriter"
"git.cryptic.systems/fh-trier/go-flucky/pkg/logger"
"git.cryptic.systems/fh-trier/go-flucky/pkg/internal/temperature" "git.cryptic.systems/fh-trier/go-flucky/pkg/internal/temperature"
"git.cryptic.systems/fh-trier/go-flucky/pkg/config" "git.cryptic.systems/fh-trier/go-flucky/pkg/config"
@ -69,6 +71,19 @@ func PrintHumidities(humidities []*types.Humidity, cnf *config.FluckyConfig, w i
tw.Flush() tw.Flush()
} }
func PrintLoggers(cnf *config.FluckyConfig, w io.Writer) {
// declare tabwriter
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
fmt.Fprintf(w, "type\tvalue\t\tlocation\n")
for _, logfile := range cnf.LogFiles[logger.LogTemperature] {
fmt.Fprintf(w, "file\t%v\t%v\n", logger.LogTemperature, logfile)
}
tw.Flush()
}
// PrintRemotes displays a list with all configured remote addresses // PrintRemotes displays a list with all configured remote addresses
func PrintRemotes(cnf *config.FluckyConfig, w io.Writer) error { func PrintRemotes(cnf *config.FluckyConfig, w io.Writer) error {