2019-06-28 11:18:55 +00:00
|
|
|
package compression
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
"github.com/Masterminds/semver"
|
2019-09-04 11:37:50 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/storage/logfile"
|
2019-06-28 11:18:55 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
var (
|
|
|
|
compression bool
|
|
|
|
configFile *string
|
|
|
|
|
|
|
|
version *semver.Version
|
|
|
|
)
|
2019-06-28 11:18:55 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
func InitCmd(cmd *cobra.Command, cnfFile *string, sverion *semver.Version) {
|
2019-06-28 11:18:55 +00:00
|
|
|
configFile = cnfFile
|
2019-09-01 10:27:06 +00:00
|
|
|
version = sverion
|
|
|
|
|
2019-06-28 11:18:55 +00:00
|
|
|
cmd.AddCommand(compressionCmd)
|
|
|
|
|
|
|
|
}
|