2019-06-28 11:12:49 +00:00
|
|
|
package convert
|
|
|
|
|
|
|
|
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:12:49 +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:12:49 +00:00
|
|
|
|
|
|
|
var convertCmd = &cobra.Command{
|
|
|
|
Use: "convert",
|
|
|
|
Short: "Convert logfiles into other markup language",
|
|
|
|
Args: cobra.ExactArgs(2),
|
|
|
|
Example: "flucky convert /var/log/flucky/logfile.json /var/log/flucky/logfile.csv",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
measuredValuesInput := logfile.New(args[0])
|
|
|
|
measuredValues, err := measuredValuesInput.Read()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if compression {
|
|
|
|
measuredValues = logfile.Compression(measuredValues)
|
|
|
|
}
|
|
|
|
|
|
|
|
measuredValuesOutput := logfile.New(args[1])
|
|
|
|
err = measuredValuesOutput.Write(measuredValues)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute a
|
2019-09-01 10:27:06 +00:00
|
|
|
func InitCmd(cmd *cobra.Command, cnfFile *string, sversion *semver.Version) {
|
2019-06-28 11:12:49 +00:00
|
|
|
configFile = cnfFile
|
2019-09-01 10:27:06 +00:00
|
|
|
version = sversion
|
|
|
|
|
2019-06-28 11:12:49 +00:00
|
|
|
cmd.AddCommand(convertCmd)
|
|
|
|
convertCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values")
|
|
|
|
}
|