PKGBUILD/cmd/compression/compression.go

48 lines
904 B
Go

package compression
import (
"log"
"github.com/Masterminds/semver"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/spf13/cobra"
)
var (
compression bool
configFile *string
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) {
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, sverion *semver.Version) {
configFile = cnfFile
version = sverion
cmd.AddCommand(compressionCmd)
}