feat(cmd/convert): new subcommand to convert logfiles
This commit is contained in:
parent
4fe4abb0e9
commit
22815231d9
@ -5,6 +5,8 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/go-flucky/flucky/cmd/convert"
|
||||
|
||||
"github.com/go-flucky/flucky/cmd/daemon"
|
||||
"github.com/go-flucky/flucky/cmd/humidity"
|
||||
"github.com/go-flucky/flucky/cmd/rgbled"
|
||||
@ -56,6 +58,7 @@ func Execute(version string) {
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file")
|
||||
|
||||
convert.InitCmd(rootCmd, configFile)
|
||||
daemon.InitCmd(rootCmd, configFile)
|
||||
humidity.InitCmd(rootCmd, configFile)
|
||||
rgbled.InitCmd(rootCmd, configFile)
|
||||
|
45
cmd/convert/convert.go
Normal file
45
cmd/convert/convert.go
Normal file
@ -0,0 +1,45 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/go-flucky/flucky/pkg/logfile"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var compression bool
|
||||
var configFile string
|
||||
|
||||
var convertCmd = &cobra.Command{
|
||||
Use: "convert",
|
||||
Short: "Convert logfiles into other markup language",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Example: "flucky convert /var/log/flucky/logfile.json /var/log/flucky/logfile.csv",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
measuredValuesInput := logfile.New(args[0])
|
||||
measuredValues, err := measuredValuesInput.Read()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if compression {
|
||||
measuredValues = logfile.Compression(measuredValues)
|
||||
}
|
||||
|
||||
measuredValuesOutput := logfile.New(args[1])
|
||||
err = measuredValuesOutput.Write(measuredValues)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// Execute a
|
||||
func InitCmd(cmd *cobra.Command, cnfFile string) {
|
||||
configFile = cnfFile
|
||||
cmd.AddCommand(convertCmd)
|
||||
convertCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values")
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package temperature
|
||||
|
||||
// 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)
|
||||
// }
|
||||
|
||||
// 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")
|
||||
// }
|
Loading…
Reference in New Issue
Block a user