PKGBUILD/cmd/temperature/convert.go

43 lines
1.1 KiB
Go
Raw Normal View History

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)
}
2019-06-21 13:43:15 +00:00
if compression {
temperatures = logfile.CompressTemperature(temperatures)
}
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")
}