feat(cmd/temperature): new subcommand to convert temperature logfiles
This commit is contained in:
parent
87475225bc
commit
e6e566793a
38
cmd/temperature/convert.go
Normal file
38
cmd/temperature/convert.go
Normal 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")
|
||||||
|
}
|
@ -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",
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user