package compression import ( "github.com/go-flucky/flucky/pkg/storage" "github.com/go-flucky/flucky/pkg/storage/logfile" "github.com/spf13/cobra" ) var ( round float64 ) // InitCmd initialize all compression subcommands func InitCmd(cmd *cobra.Command) error { compressionCmd := &cobra.Command{ Use: "compression", Short: "Compress a logfile", Args: cobra.ExactArgs(1), Example: "flucky compression /var/log/flucky/logfile.csv", RunE: run, } compressionCmd.Flags().Float64Var(&round, "round", 0, "Round values. The value 0 deactivates the function") cmd.AddCommand(compressionCmd) return nil } func run(cmd *cobra.Command, args []string) error { logfileInput := logfile.New(args[0]) measuredValues, err := logfileInput.Read() if err != nil { return err } if round != 0 { storage.Round(measuredValues, round) } storage.Compression(measuredValues) err = logfileInput.Write(measuredValues) if err != nil { return err } return nil }