feat: list configured loggers
This commit is contained in:
parent
88f6116a41
commit
3d54401011
40
cmd/logger/list.go
Normal file
40
cmd/logger/list.go
Normal 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)
|
||||
}
|
@ -5,6 +5,8 @@ import (
|
||||
"io"
|
||||
"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/config"
|
||||
@ -69,6 +71,19 @@ func PrintHumidities(humidities []*types.Humidity, cnf *config.FluckyConfig, w i
|
||||
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
|
||||
func PrintRemotes(cnf *config.FluckyConfig, w io.Writer) error {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user