53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package compression
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/Masterminds/semver"
|
|
"github.com/go-flucky/flucky/pkg/storage"
|
|
"github.com/go-flucky/flucky/pkg/storage/logfile"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
configFile *string
|
|
round float64
|
|
version *semver.Version
|
|
)
|
|
|
|
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) {
|
|
|
|
logfileInput := logfile.New(args[0])
|
|
measuredValues, err := logfileInput.Read()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
if round != 0 {
|
|
storage.Round(measuredValues, round)
|
|
}
|
|
|
|
storage.Compression(measuredValues)
|
|
|
|
err = logfileInput.Write(measuredValues)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
},
|
|
}
|
|
|
|
func InitCmd(cmd *cobra.Command, cnfFile *string, sverion *semver.Version) {
|
|
configFile = cnfFile
|
|
version = sverion
|
|
|
|
cmd.AddCommand(compressionCmd)
|
|
compressionCmd.Flags().Float64Var(&round, "round", 0, "Round values. The value 0 deactivates the function")
|
|
|
|
}
|