feat(cmd/compression): new subcommand to compress logfiles
This commit is contained in:
		@@ -5,6 +5,7 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/go-flucky/flucky/cmd/compression"
 | 
			
		||||
	"github.com/go-flucky/flucky/cmd/convert"
 | 
			
		||||
 | 
			
		||||
	"github.com/go-flucky/flucky/cmd/daemon"
 | 
			
		||||
@@ -58,6 +59,7 @@ func Execute(version string) {
 | 
			
		||||
 | 
			
		||||
	rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file")
 | 
			
		||||
 | 
			
		||||
	compression.InitCmd(rootCmd, configFile)
 | 
			
		||||
	convert.InitCmd(rootCmd, configFile)
 | 
			
		||||
	daemon.InitCmd(rootCmd, configFile)
 | 
			
		||||
	humidity.InitCmd(rootCmd, configFile)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										40
									
								
								cmd/compression/compression.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								cmd/compression/compression.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
package compression
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/logfile"
 | 
			
		||||
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var compression bool
 | 
			
		||||
var configFile string
 | 
			
		||||
 | 
			
		||||
var compressionCmd = &cobra.Command{
 | 
			
		||||
	Use:     "compression",
 | 
			
		||||
	Short:   "Compress a logfile",
 | 
			
		||||
	Args:    cobra.ExactArgs(1),
 | 
			
		||||
	Example: "flucky compression /var/log/flucky/logfile.csv",
 | 
			
		||||
	Run: func(cmd *cobra.Command, args []string) {
 | 
			
		||||
 | 
			
		||||
		measuredValueLogfile := logfile.New(args[0])
 | 
			
		||||
		measuredValues, err := measuredValueLogfile.Read()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatalln(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		measuredValues = logfile.Compression(measuredValues)
 | 
			
		||||
 | 
			
		||||
		err = measuredValueLogfile.Write(measuredValues)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatalln(err)
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func InitCmd(cmd *cobra.Command, cnfFile string) {
 | 
			
		||||
	configFile = cnfFile
 | 
			
		||||
	cmd.AddCommand(compressionCmd)
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
package temperature
 | 
			
		||||
 | 
			
		||||
// var compressTemperatureCmd = &cobra.Command{
 | 
			
		||||
// 	Use:   "compress",
 | 
			
		||||
// 	Short: "Compress temperature logfiles",
 | 
			
		||||
// 	Args:  cobra.ExactArgs(1),
 | 
			
		||||
// 	Example: `flucky temperature compress /var/log/flucky/temperature.json
 | 
			
		||||
// flucky temperature compress /var/log/flucky/temperature.xml`,
 | 
			
		||||
// 	Run: func(cmd *cobra.Command, args []string) {
 | 
			
		||||
 | 
			
		||||
// 		temperatureLogfile := logfile.New(args[0])
 | 
			
		||||
// 		temperatures, err := temperatureLogfile.ReadTemperatures()
 | 
			
		||||
// 		if err != nil {
 | 
			
		||||
// 			log.Fatalln(err)
 | 
			
		||||
// 		}
 | 
			
		||||
 | 
			
		||||
// 		temperatures = logfile.CompressTemperature(temperatures)
 | 
			
		||||
 | 
			
		||||
// 		err = temperatureLogfile.WriteTemperatures(temperatures)
 | 
			
		||||
// 		if err != nil {
 | 
			
		||||
// 			log.Fatalln(err)
 | 
			
		||||
// 		}
 | 
			
		||||
// 	},
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
// func init() {
 | 
			
		||||
// 	temperatureCmd.AddCommand(compressTemperatureCmd)
 | 
			
		||||
// }
 | 
			
		||||
		Reference in New Issue
	
	Block a user