feat(cmd/temperature): new subcommand to convert temperature logfiles

This commit is contained in:
Markus Pesch 2019-06-21 12:12:25 +02:00
parent 87475225bc
commit e6e566793a
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
3 changed files with 40 additions and 2 deletions

View File

@ -0,0 +1,38 @@
package temperature
import (
"log"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/spf13/cobra"
)
var logfileInput string
var logfileOutput string
var convertTemperatureCmd = &cobra.Command{
Use: "convert",
Short: "Convert temperature logfiles into other markup language",
Args: cobra.ExactArgs(2),
Example: "flucky temperature convert /var/log/flucky/temperature.json /var/log/flucky/temperature.xml",
Run: func(cmd *cobra.Command, args []string) {
temperatureLogfileInput := logfile.New(args[0])
temperatures, err := temperatureLogfileInput.ReadTemperatures()
if err != nil {
log.Fatalln(err)
}
temperatureLogfileOutput := logfile.New(args[1])
err = temperatureLogfileOutput.WriteTemperatures(temperatures)
if err != nil {
log.Fatalln(err)
}
},
}
func init() {
temperatureCmd.AddCommand(convertTemperatureCmd)
convertTemperatureCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values")
convertTemperatureCmd.Flags().Float64Var(&round, "round", 0.25, "Round values. The value 0 deactivates the function")
}

View File

@ -12,9 +12,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var compression bool
var logs bool var logs bool
var round float64
var readTemperatureCmd = &cobra.Command{ var readTemperatureCmd = &cobra.Command{
Use: "read", Use: "read",

View File

@ -6,7 +6,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var compression bool
var configFile string var configFile string
var round float64
var temperatureCmd = &cobra.Command{ var temperatureCmd = &cobra.Command{
Use: "temperature", Use: "temperature",