PKGBUILD/cmd/convert/convert.go

46 lines
1002 B
Go

package convert
import (
"log"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/spf13/cobra"
)
var compression bool
var configFile string
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
func InitCmd(cmd *cobra.Command, cnfFile string) {
configFile = cnfFile
cmd.AddCommand(convertCmd)
convertCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values")
}