mirror of https://github.com/on4kjm/FLEcli.git
parent
6134577dd0
commit
0b9fb5bc78
@ -1,93 +0,0 @@
|
||||
package cmd
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
// "log"
|
||||
//"strings"
|
||||
)
|
||||
|
||||
var outputFilename string
|
||||
var isWWFFcli bool
|
||||
var isSOTAcli bool
|
||||
var isOverwrite bool
|
||||
|
||||
// adifCmd is executed when choosing the adif option (load and generate adif file)
|
||||
var adifCmd = &cobra.Command{
|
||||
Use: "adif",
|
||||
Short: "Generates an ADIF file based on a FLE type shorthand logfile.",
|
||||
// Long: `A longer description that spans multiple lines and likely contains examples
|
||||
// and usage of using your command. For example:
|
||||
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
processAdifCommand()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(adifCmd)
|
||||
|
||||
adifCmd.PersistentFlags().StringVarP(&inputFilename, "input", "i", "", "FLE formatted input file (mandatory)")
|
||||
adifCmd.MarkPersistentFlagRequired("input")
|
||||
adifCmd.PersistentFlags().BoolVarP(&isInterpolateTime, "interpolate", "", false, "Interpolates the missing time entries.")
|
||||
|
||||
adifCmd.PersistentFlags().BoolVarP(&isWWFFcli, "wwff", "w", false, "Generates a WWFF ready ADIF file.")
|
||||
adifCmd.PersistentFlags().BoolVarP(&isSOTAcli, "sota", "s", false, "Generates a SOTA ready ADIF file.")
|
||||
adifCmd.PersistentFlags().BoolVarP(&isOverwrite, "overwrite", "", false, "Overwrites the output file if it exisits")
|
||||
adifCmd.PersistentFlags().StringVarP(&outputFilename, "output", "o", "", "Output filename")
|
||||
}
|
||||
|
||||
func processAdifCommand() {
|
||||
|
||||
verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputFilename, inputFilename, isOverwrite, ".adi")
|
||||
|
||||
// if the output file could not be parsed correctly do noting
|
||||
if filenameWasOK {
|
||||
loadedLogFile, isLoadedOK := loadFile()
|
||||
|
||||
//TODO: move this in a function so that it can be more easily tested
|
||||
if isLoadedOK {
|
||||
if len(loadedLogFile) == 0 {
|
||||
fmt.Println("No useful data read. Aborting...")
|
||||
return
|
||||
}
|
||||
|
||||
//TODO: There are more tests required here
|
||||
//check if we have the necessary information for the type
|
||||
if isWWFFcli {
|
||||
if loadedLogFile[0].MyWWFF == "" {
|
||||
fmt.Println("Missing MY-WWFF reference. Aborting...")
|
||||
return
|
||||
}
|
||||
if loadedLogFile[0].Operator == "" {
|
||||
fmt.Println("Missing Operator. Aborting...")
|
||||
return
|
||||
}
|
||||
}
|
||||
if isSOTAcli {
|
||||
if loadedLogFile[0].MySOTA == "" {
|
||||
fmt.Println("Missing MY-SOTA reference. Aborting...")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
outputAdif(verifiedOutputFilename, loadedLogFile, isWWFFcli, isSOTAcli)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package flecmd
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"FLEcli/fleprocess"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var outputFilename string
|
||||
var isWWFFcli bool
|
||||
var isSOTAcli bool
|
||||
var isOverwrite bool
|
||||
|
||||
// adifCmd is executed when choosing the adif option (load and generate adif file)
|
||||
var adifCmd = &cobra.Command{
|
||||
Use: "adif [flags] inputFile [outputFile]",
|
||||
Short: "Generates an ADIF file based on a FLE type shorthand logfile.",
|
||||
// Long: `A longer description that spans multiple lines and likely contains examples
|
||||
// and usage of using your command. For example:
|
||||
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
//if args is empty, throw an error
|
||||
if len(args) == 0 {
|
||||
//TODO: fix this ugly statement (because I am lazy)
|
||||
return fmt.Errorf("Missing input file %s", "")
|
||||
}
|
||||
inputFilename = args[0]
|
||||
if len(args) == 2 {
|
||||
outputFilename = args[1]
|
||||
}
|
||||
if len(args) > 2 {
|
||||
return fmt.Errorf("Too many arguments.%s", "")
|
||||
}
|
||||
|
||||
fleprocess.ProcessAdifCommand(
|
||||
inputFilename,
|
||||
outputFilename,
|
||||
isInterpolateTime,
|
||||
isWWFFcli,
|
||||
isSOTAcli,
|
||||
isOverwrite)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(adifCmd)
|
||||
|
||||
adifCmd.PersistentFlags().BoolVarP(&isInterpolateTime, "interpolate", "i", false, "Interpolates the missing time entries.")
|
||||
adifCmd.PersistentFlags().BoolVarP(&isWWFFcli, "wwff", "w", false, "Generates a WWFF ready ADIF file.")
|
||||
adifCmd.PersistentFlags().BoolVarP(&isSOTAcli, "sota", "s", false, "Generates a SOTA ready ADIF file.")
|
||||
adifCmd.PersistentFlags().BoolVarP(&isOverwrite, "overwrite", "o", false, "Overwrites the output file if it exisits")
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package flecmd
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"FLEcli/fleprocess"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var outputCsvFilename string
|
||||
var isOverwriteCsv bool
|
||||
|
||||
// csvCmd is executed when choosing the csv option (load FLE file and generate csv file)
|
||||
var csvCmd = &cobra.Command{
|
||||
Use: "csv [flags] inputFile [outputFile]",
|
||||
Short: "Generates a SOTA .csv file based on a FLE type shorthand logfile.",
|
||||
// Long: `A longer description that spans multiple lines and likely contains examples
|
||||
// and usage of using your command. For example:
|
||||
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
//if args is empty, throw an error
|
||||
if len(args) == 0 {
|
||||
//TODO: fix this ugly statement (because I am lazy)
|
||||
return fmt.Errorf("Missing input file %s", "")
|
||||
}
|
||||
inputFilename = args[0]
|
||||
if len(args) == 2 {
|
||||
outputCsvFilename = args[1]
|
||||
}
|
||||
if len(args) > 2 {
|
||||
return fmt.Errorf("Too many arguments.%s", "")
|
||||
}
|
||||
|
||||
|
||||
//TODO: should return an error
|
||||
fleprocess.ProcessCsvCommand(inputFilename, outputCsvFilename, isInterpolateTime, isOverwriteCsv)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(csvCmd)
|
||||
|
||||
csvCmd.PersistentFlags().BoolVarP(&isInterpolateTime, "interpolate", "i", false, "Interpolates the missing time entries.")
|
||||
|
||||
csvCmd.PersistentFlags().BoolVarP(&isOverwriteCsv, "overwrite", "o", false, "Overwrites the output file if it exisits")
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package flecmd
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"FLEcli/fleprocess"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// loadCmd represents the load command
|
||||
var loadCmd = &cobra.Command{
|
||||
Use: "load [flags] inputFile",
|
||||
Short: "Loads and validates a FLE type shorthand logfile",
|
||||
// Long: `A longer description that spans multiple lines and likely contains examples
|
||||
// and usage of using your command. For example:
|
||||
|
||||
// Cobra is a CLI library for Go that empowers applications.
|
||||
// This application is a tool to generate the needed files
|
||||
// to quickly create a Cobra application.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
//if args is empty, throw an error
|
||||
if len(args) == 0 {
|
||||
//TODO: fix this ugly statement (because I am lazy)
|
||||
return fmt.Errorf("Missing input file %s","")
|
||||
}
|
||||
if len(args) > 1 {
|
||||
return fmt.Errorf("Too many arguments.%s","")
|
||||
}
|
||||
inputFilename = args[0]
|
||||
fleprocess.LoadFile(inputFilename, isInterpolateTime)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(loadCmd)
|
||||
|
||||
loadCmd.PersistentFlags().BoolVarP(&isInterpolateTime, "interpolate", "i", false, "Interpolates the missing time entries.")
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package flecmd
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
@ -0,0 +1,60 @@
|
||||
package fleprocess
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//ProcessAdifCommand FIXME
|
||||
func ProcessAdifCommand(inputFilename, outputFilename string, isInterpolateTime, isWWFFcli, isSOTAcli, isOverwrite bool) {
|
||||
|
||||
verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputFilename, inputFilename, isOverwrite, ".adi")
|
||||
|
||||
// if the output file could not be parsed correctly do noting
|
||||
if filenameWasOK {
|
||||
loadedLogFile, isLoadedOK := LoadFile(inputFilename,isInterpolateTime)
|
||||
|
||||
if isLoadedOK {
|
||||
if len(loadedLogFile) == 0 {
|
||||
fmt.Println("No useful data read. Aborting...")
|
||||
return
|
||||
}
|
||||
|
||||
//TODO: There are more tests required here
|
||||
//check if we have the necessary information for the type
|
||||
if isWWFFcli {
|
||||
if loadedLogFile[0].MyWWFF == "" {
|
||||
fmt.Println("Missing MY-WWFF reference. Aborting...")
|
||||
return
|
||||
}
|
||||
if loadedLogFile[0].Operator == "" {
|
||||
fmt.Println("Missing Operator. Aborting...")
|
||||
return
|
||||
}
|
||||
}
|
||||
if isSOTAcli {
|
||||
if loadedLogFile[0].MySOTA == "" {
|
||||
fmt.Println("Missing MY-SOTA reference. Aborting...")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
OutputAdif(verifiedOutputFilename, loadedLogFile, isWWFFcli, isSOTAcli)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
import (
|
||||
"reflect"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
import "testing"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
import (
|
||||
"reflect"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
import (
|
||||
"errors"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
import (
|
||||
"os"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
import (
|
||||
"reflect"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package fleprocess
|
||||
|
||||
/*
|
||||
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "# Usage" > help.txt
|
||||
echo " " >> help.txt
|
||||
echo " " >> help.txt
|
||||
|
||||
echo "## Overview" >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
../dist/FLEcli_darwin_amd64/FLEcli >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
echo " " >> help.txt
|
||||
echo " " >> help.txt
|
||||
|
||||
echo "## \"LOAD\" command" >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
../dist/FLEcli_darwin_amd64/FLEcli load --help >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
echo " " >> help.txt
|
||||
echo " " >> help.txt
|
||||
|
||||
echo "## \"ADIF\" command" >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
../dist/FLEcli_darwin_amd64/FLEcli adif --help >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
echo " " >> help.txt
|
||||
echo " " >> help.txt
|
||||
|
||||
echo "## \"CSV\" command" >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
../dist/FLEcli_darwin_amd64/FLEcli csv --help >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
echo " " >> help.txt
|
||||
echo " " >> help.txt
|
||||
|
||||
echo "## \"VERSION\" command" >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
../dist/FLEcli_darwin_amd64/FLEcli version --help >> help.txt
|
||||
echo "\`\`\`" >> help.txt
|
||||
|
||||
echo "The normal output looks like \`FLEcli version: v0.1.2\`. The detailled output gives additionaly the Git commit hash. the date and time of build and who built the release." >> help.txt
|
Loading…
Reference in new issue