diff --git a/cmd/cmd.go b/cmd/cmd.go index e6ee7ad..a8ccef2 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -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) diff --git a/cmd/convert/convert.go b/cmd/convert/convert.go new file mode 100644 index 0000000..d5d67e5 --- /dev/null +++ b/cmd/convert/convert.go @@ -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") + +} diff --git a/cmd/temperature/convert.go b/cmd/temperature/convert.go deleted file mode 100644 index 12ece2a..0000000 --- a/cmd/temperature/convert.go +++ /dev/null @@ -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") -// }