diff --git a/.gitignore b/.gitignore index 6860813..3099afc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ FLEcli test/output/temp/* dist/* +notes/help.txt # Test binary, built with `go test -c` *.test diff --git a/.goreleaser.yml b/.goreleaser.yml index c8d50ed..b84f3a5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,7 +18,7 @@ builds: - goos: windows goarch: amd64 ldflags: - - -s -w -X FLEcli/cmd.version={{.Version}} -X FLEcli/cmd.commit={{.Commit}} -X FLEcli/cmd.date={{.Date}} -X=FLEcli/cmd.builtBy=goReleaser + - -s -w -X FLEcli/flecmd.version={{.Version}} -X FLEcli/flecmd.commit={{.Commit}} -X FLEcli/flecmd.date={{.Date}} -X=FLEcli/flecmd.builtBy=goReleaser env: - CGO_ENABLED=0 diff --git a/README.md b/README.md index de433a2..465e60d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Most comon use cases are described hereafter as examples. To load and validate the FLE formated file (`myActivation.txt`: ``` -./FLEcli load -i=myActivation.txt +./FLEcli load myActivation.txt ``` This command will parse and display the QSOs in grid format. Fields that couldn't be successfully parsed are prefixed with "*". @@ -48,21 +48,21 @@ Parsing errors or doubts are listed at the end of the list. To generate an ADIF file based on `activation.txt`: ``` -./FLEcli adif -i activation.txt -o output/activation.adi --overwrite --interpolate +./FLEcli adif -i --overwrite activation.txt output/activation.adi ``` -The `-o` (or the long form, `--output`) specifies the path and name of the output file. -If the flag and value are omitted, the tool will generate a filename. +The second element after the input specifies the path and name of the output file. +If is omitted, the tool will generate a filename. It is based on the input filename, just replacing the extension with `.adi`. -The `--overwrite` flag indicates that, if the output file already exists, it should be overwritten. +The `-o` or `--overwrite` flag indicates that, if the output file already exists, it should be overwritten. -The `--interpolate` flag will interpolate the missing non-entered times based on the first and the last entered time. +The `-i` or `--interpolate` flag will interpolate the missing non-entered times based on the first and the last entered time. ### Example: generate an ADIF file for WWFF upload To generate a WWFF-ready ADIF file: ``` -./FLEcli adif -i ON4KJM@ONFF-025920200524.txt --wwff --interpolate +./FLEcli adif -i --wwff ON4KJM@ONFF-025920200524.txt ``` The `--wwff` indicates the adif flavour to produce. You can use the `--sota` switch to generate an ADIF file containing SOTA details. @@ -76,7 +76,11 @@ As we didn't provide an output filename, the default output, `ON4KJM@ONFF-025920 To generate a CSV file that can be uploaded to https://www.sotadata.org.uk/ to report SOTA activations: ``` -./FLEcli csv -i sotaActivation.txt --overwrite --interpolate +./FLEcli csv --interpolate --overwrite sotaActivation.txt +``` +or the short form +``` +./FLEcli csv -i -o sotaActivation.txt ``` This command will generate `sotaActivation.csv` based on the `sotaActivation.txt` FLE logfile. If the output file exists, it will be overwritten as the `--overwrite` flag has been specified. diff --git a/build.sh b/build.sh index 0e148cb..bd7099e 100755 --- a/build.sh +++ b/build.sh @@ -8,4 +8,4 @@ commitRef=$(git rev-parse HEAD) tag=$(git describe --tags) version="${tag}_(PrivateBuild)" buildDate=$(date -u +"%FT%TZ") -go build -ldflags="-s -w -X=FLEcli/cmd.version=${version} -X=FLEcli/cmd.commit=${commitRef} -X=FLEcli/cmd.date=${buildDate} -X=FLEcli/cmd.builtBy=${USER}" +go build -ldflags="-s -w -X=FLEcli/flecmd.version=${version} -X=FLEcli/flecmd.commit=${commitRef} -X=FLEcli/flecmd.date=${buildDate} -X=FLEcli/flecmd.builtBy=${USER}" diff --git a/cmd/adif.go b/cmd/adif.go deleted file mode 100644 index 165728d..0000000 --- a/cmd/adif.go +++ /dev/null @@ -1,93 +0,0 @@ -package cmd - -/* -Copyright © 2020 Jean-Marc Meessen, ON4KJM - -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) - } - } -} diff --git a/doc/usage.md b/doc/usage.md index 81f4f2a..59759b5 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -1,7 +1,10 @@ # Usage - + + ## Overview ``` +A Command Line "Fast Log Entry" (FLE) processor + Usage: FLEcli [command] @@ -18,69 +21,62 @@ Flags: Use "FLEcli [command] --help" for more information about a command. ``` - - + + ## "LOAD" command ``` -FLEcli load --help Loads and validates a FLE type shorthand logfile Usage: - FLEcli load [flags] + FLEcli load [flags] inputFile Flags: - -h, --help help for load - -i, --input string FLE formatted input file (mandatory) - --interpolate Interpolates the missing time entries. + -h, --help help for load + -i, --interpolate Interpolates the missing time entries. Global Flags: --config string config file (default is $HOME/.FLEcli.yaml) ``` - - + + ## "ADIF" command ``` -FLEcli adif --help Generates an ADIF file based on a FLE type shorthand logfile. Usage: - FLEcli adif [flags] + FLEcli adif [flags] inputFile [outputFile] Flags: - -h, --help help for adif - -i, --input string FLE formatted input file (mandatory) - --interpolate Interpolates the missing time entries. - -o, --output string Output filename - --overwrite Overwrites the output file if it exisits - -s, --sota Generates a SOTA ready ADIF file. - -w, --wwff Generates a WWFF ready ADIF file. + -h, --help help for adif + -i, --interpolate Interpolates the missing time entries. + -o, --overwrite Overwrites the output file if it exisits + -s, --sota Generates a SOTA ready ADIF file. + -w, --wwff Generates a WWFF ready ADIF file. Global Flags: --config string config file (default is $HOME/.FLEcli.yaml) ``` - + + ## "CSV" command ``` -FLEcli csv --help Generates a SOTA .csv file based on a FLE type shorthand logfile. Usage: - FLEcli csv [flags] + FLEcli csv [flags] inputFile [outputFile] Flags: - -h, --help help for csv - -i, --input string FLE formatted input file (mandatory) - --interpolate Interpolates the missing time entries. - -o, --output string Output filename - --overwrite Overwrites the output file if it exisits + -h, --help help for csv + -i, --interpolate Interpolates the missing time entries. + -o, --overwrite Overwrites the output file if it exisits Global Flags: --config string config file (default is $HOME/.FLEcli.yaml) ``` - + + ## "VERSION" command ``` -FLEcli version --help "version" will output the current build information Usage: @@ -93,4 +89,4 @@ Flags: Global Flags: --config string config file (default is $HOME/.FLEcli.yaml) ``` -The normal output looks like `FLEcli version: v0.0.1`. The detailled output gives additionaly the Git commit hash. the date and time of build and who built the release. \ No newline at end of file +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. diff --git a/flecmd/adif.go b/flecmd/adif.go new file mode 100644 index 0000000..367ef16 --- /dev/null +++ b/flecmd/adif.go @@ -0,0 +1,71 @@ +package flecmd + +/* +Copyright © 2020 Jean-Marc Meessen, ON4KJM + +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") +} diff --git a/flecmd/csv.go b/flecmd/csv.go new file mode 100644 index 0000000..22f62ae --- /dev/null +++ b/flecmd/csv.go @@ -0,0 +1,64 @@ +package flecmd + +/* +Copyright © 2020 Jean-Marc Meessen, ON4KJM + +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") +} + diff --git a/flecmd/load.go b/flecmd/load.go new file mode 100644 index 0000000..94ce1d6 --- /dev/null +++ b/flecmd/load.go @@ -0,0 +1,57 @@ +package flecmd + +/* +Copyright © 2020 Jean-Marc Meessen, ON4KJM + +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.") +} + + diff --git a/cmd/root.go b/flecmd/root.go similarity index 99% rename from cmd/root.go rename to flecmd/root.go index 37c79cf..d903bf6 100644 --- a/cmd/root.go +++ b/flecmd/root.go @@ -1,4 +1,4 @@ -package cmd +package flecmd /* Copyright © 2020 Jean-Marc Meessen, ON4KJM diff --git a/cmd/version.go b/flecmd/version.go similarity index 94% rename from cmd/version.go rename to flecmd/version.go index e69902c..d8a7d1b 100644 --- a/cmd/version.go +++ b/flecmd/version.go @@ -1,4 +1,4 @@ -package cmd +package flecmd /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -24,16 +24,16 @@ THE SOFTWARE. import ( "fmt" - "time" "github.com/spf13/cobra" + "time" ) var ( - detailed = false - version = "private build" - commit = "none" - date = "unknown" - builtBy = "" + detailed = false + version = "private build" + commit = "none" + date = "unknown" + builtBy = "" versionCmd = &cobra.Command{ Use: "version", Short: "\"version\" will output the current build information", diff --git a/cmd/csv.go b/fleprocess/CSV_process.go similarity index 53% rename from cmd/csv.go rename to fleprocess/CSV_process.go index 6240b17..72c2432 100644 --- a/cmd/csv.go +++ b/fleprocess/CSV_process.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -16,46 +16,20 @@ See the License for the specific language governing permissions and limitations under the License. */ -//Documentation of SOTA CSV format: https://www.sotadata.org.uk/en/upload/activator/csv/info +//Documentation of SOTA CSV format: https://www.sotadata.org.uk/en/upload/activator/csv/info import ( "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", - 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: - - Run: func(cmd *cobra.Command, args []string) { - processCsvCommand() - }, -} - -func init() { - rootCmd.AddCommand(csvCmd) - - csvCmd.PersistentFlags().StringVarP(&inputFilename, "input", "i", "", "FLE formatted input file (mandatory)") - csvCmd.MarkPersistentFlagRequired("input") - csvCmd.PersistentFlags().BoolVarP(&isInterpolateTime, "interpolate", "", false, "Interpolates the missing time entries.") - - csvCmd.PersistentFlags().BoolVarP(&isOverwriteCsv, "overwrite", "", false, "Overwrites the output file if it exisits") - csvCmd.PersistentFlags().StringVarP(&outputCsvFilename, "output", "o", "", "Output filename") -} - -func processCsvCommand() { +//ProcessCsvCommand loads an FLE input to produce a SOTA CSV +func ProcessCsvCommand(inputFilename, outputCsvFilename string, isInterpolateTime, isOverwriteCsv bool) { verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputCsvFilename, inputFilename, isOverwriteCsv, ".csv") // if the output file could not be parsed correctly do noting if filenameWasOK { - loadedLogFile, isLoadedOK := loadFile() + loadedLogFile, isLoadedOK := LoadFile(inputFilename, isInterpolateTime) //TODO: move this in a function so that it can be more easily tested if isLoadedOK { diff --git a/fleprocess/adif_process.go b/fleprocess/adif_process.go new file mode 100644 index 0000000..2b3f41b --- /dev/null +++ b/fleprocess/adif_process.go @@ -0,0 +1,60 @@ +package fleprocess + +/* +Copyright © 2020 Jean-Marc Meessen, ON4KJM + +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) + } + } +} diff --git a/cmd/adif_write.go b/fleprocess/adif_write.go similarity index 95% rename from cmd/adif_write.go rename to fleprocess/adif_write.go index c336998..9d4d2e4 100644 --- a/cmd/adif_write.go +++ b/fleprocess/adif_write.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -24,8 +24,8 @@ import ( "time" ) -// outputAdif generates and writes data in ADIF format -func outputAdif(outputFile string, fullLog []LogLine, isWWFF bool, isSOTA bool) { +// OutputAdif generates and writes data in ADIF format +func OutputAdif(outputFile string, fullLog []LogLine, isWWFF bool, isSOTA bool) { //convert the log data to an in-memory ADIF file adifData := buildAdif(fullLog, isWWFF, isSOTA) @@ -56,10 +56,10 @@ func buildAdif(fullLog []LogLine, isWWFF bool, isSOTA bool) (adifList []string) adifLine.WriteString(adifElement("RST_SENT", logLine.RSTsent)) adifLine.WriteString(adifElement("RST_RCVD", logLine.RSTrcvd)) if logLine.Comment != "" { - adifLine.WriteString(adifElement("COMMENT", logLine.Comment)) + adifLine.WriteString(adifElement("COMMENT", logLine.Comment)) } if logLine.OMname != "" { - adifLine.WriteString(adifElement("NAME", logLine.OMname)) + adifLine.WriteString(adifElement("NAME", logLine.OMname)) } if logLine.QSLmsg != "" { adifLine.WriteString(adifElement("QSLMSG", logLine.QSLmsg)) diff --git a/cmd/adif_write_test.go b/fleprocess/adif_write_test.go similarity index 99% rename from cmd/adif_write_test.go rename to fleprocess/adif_write_test.go index 9aae610..987b797 100644 --- a/cmd/adif_write_test.go +++ b/fleprocess/adif_write_test.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess import ( "reflect" diff --git a/cmd/braketedData.go b/fleprocess/braketedData.go similarity index 98% rename from cmd/braketedData.go rename to fleprocess/braketedData.go index dd4eab7..19e79ec 100644 --- a/cmd/braketedData.go +++ b/fleprocess/braketedData.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM diff --git a/cmd/braketedData_test.go b/fleprocess/braketedData_test.go similarity index 98% rename from cmd/braketedData_test.go rename to fleprocess/braketedData_test.go index b63e711..7597e18 100644 --- a/cmd/braketedData_test.go +++ b/fleprocess/braketedData_test.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess import "testing" diff --git a/cmd/csv_write.go b/fleprocess/csv_write.go similarity index 91% rename from cmd/csv_write.go rename to fleprocess/csv_write.go index 04b3a6c..b595ed6 100644 --- a/cmd/csv_write.go +++ b/fleprocess/csv_write.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -48,14 +48,14 @@ func buildCsv(fullLog []LogLine) (csvList []string) { csvLine.WriteString(fmt.Sprintf(",%s", logLine.Time)) //TODO: Should we test the result _, _, _, sotaBand := IsBand(logLine.Band) - csvLine.WriteString(fmt.Sprintf(",%s",sotaBand )) - csvLine.WriteString(fmt.Sprintf(",%s",logLine.Mode)) + csvLine.WriteString(fmt.Sprintf(",%s", sotaBand)) + csvLine.WriteString(fmt.Sprintf(",%s", logLine.Mode)) csvLine.WriteString(fmt.Sprintf(",%s", logLine.Call)) if logLine.SOTA != "" { - csvLine.WriteString(fmt.Sprintf(",%s", logLine.SOTA)) + csvLine.WriteString(fmt.Sprintf(",%s", logLine.SOTA)) } else { if logLine.Comment != "" { - csvLine.WriteString(",") + csvLine.WriteString(",") } } if logLine.Comment != "" { @@ -67,7 +67,6 @@ func buildCsv(fullLog []LogLine) (csvList []string) { return csvList } - //adifDate converts a date in YYYY-MM-DD format to YYYYMMDD func csvDate(inputDate string) (outputDate string) { const FLEdateFormat = "2006-01-02" diff --git a/cmd/csv_write_test.go b/fleprocess/csv_write_test.go similarity index 96% rename from cmd/csv_write_test.go rename to fleprocess/csv_write_test.go index 4055362..6fccebc 100644 --- a/cmd/csv_write_test.go +++ b/fleprocess/csv_write_test.go @@ -1,11 +1,11 @@ -package cmd +package fleprocess import ( "reflect" "testing" ) -func Test_csvDate(t *testing.T) { +func Test_csvDate(t *testing.T) { type args struct { inputDate string } diff --git a/cmd/displayLog.go b/fleprocess/displayLog.go similarity index 99% rename from cmd/displayLog.go rename to fleprocess/displayLog.go index 69e362a..336038b 100644 --- a/cmd/displayLog.go +++ b/fleprocess/displayLog.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM diff --git a/cmd/inferTime.go b/fleprocess/inferTime.go similarity index 99% rename from cmd/inferTime.go rename to fleprocess/inferTime.go index a8d5f0a..d81533f 100644 --- a/cmd/inferTime.go +++ b/fleprocess/inferTime.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess import ( "errors" diff --git a/cmd/inferTime_test.go b/fleprocess/inferTime_test.go similarity index 99% rename from cmd/inferTime_test.go rename to fleprocess/inferTime_test.go index 0249d93..ca5cb2d 100644 --- a/cmd/inferTime_test.go +++ b/fleprocess/inferTime_test.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess import ( "fmt" diff --git a/cmd/load.go b/fleprocess/load_file.go similarity index 86% rename from cmd/load.go rename to fleprocess/load_file.go index 015231c..b0c603c 100644 --- a/cmd/load.go +++ b/fleprocess/load_file.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -23,53 +23,11 @@ import ( "os" "regexp" "time" - - //"time" - - "github.com/spf13/cobra" - //"strings" ) -// loadCmd represents the load command -var loadCmd = &cobra.Command{ - Use: "load", - 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.`, - Run: func(cmd *cobra.Command, args []string) { - //fmt.Println("load called") - //fmt.Println("Inputfile: ",inputFilename) - loadFile() - }, -} - -func init() { - rootCmd.AddCommand(loadCmd) - - loadCmd.PersistentFlags().StringVarP(&inputFilename, "input", "i", "", "FLE formatted input file (mandatory)") - loadCmd.MarkPersistentFlagRequired("input") - - loadCmd.PersistentFlags().BoolVarP(&isInterpolateTime, "interpolate", "", false, "Interpolates the missing time entries.") - - // rootCmd.PersistentFlags().StringVarP(&inputFilename, "input", "i", "", "FLE formatted input file (mandatory)") - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // loadCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // loadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") -} - +//LoadFile FIXME //returns nill if failure to process -func loadFile() (filleFullLog []LogLine, isProcessedOK bool) { +func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogLine, isProcessedOK bool) { file, err := os.Open(inputFilename) if err != nil { @@ -364,4 +322,4 @@ func displayLogSimple(fullLog []LogLine) { fmt.Print(SprintLogInColumn(filledLogLine)) } -} +} \ No newline at end of file diff --git a/cmd/output_filename.go b/fleprocess/output_filename.go similarity index 93% rename from cmd/output_filename.go rename to fleprocess/output_filename.go index c5ff23f..eb59247 100644 --- a/cmd/output_filename.go +++ b/fleprocess/output_filename.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -17,16 +17,12 @@ limitations under the License. */ import ( - "os" "fmt" + "os" "path/filepath" ) -// does the target file exist? -// is the file defined -// remove the extention - -//returning "" is considered as invalid +//buildOutputFilname will try to figure out an output filename (for the case none was provided) func buildOutputFilename(output string, input string, overwrite bool, newExtension string) (outputFilename string, wasOK bool) { outputFilename = "" diff --git a/cmd/output_filename_test.go b/fleprocess/output_filename_test.go similarity index 99% rename from cmd/output_filename_test.go rename to fleprocess/output_filename_test.go index 68b1ebb..d6dfcb8 100644 --- a/cmd/output_filename_test.go +++ b/fleprocess/output_filename_test.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess import ( "os" diff --git a/cmd/parse_line.go b/fleprocess/parse_line.go similarity index 99% rename from cmd/parse_line.go rename to fleprocess/parse_line.go index e5d2952..2bd1854 100644 --- a/cmd/parse_line.go +++ b/fleprocess/parse_line.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -235,9 +235,9 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // If the "sota" keyword is used, skip it if regexpIsSotaKeyWord.MatchString(element) { - // this keyword is not supported anymore with FLE 3 and doesn't add any value + // this keyword is not supported anymore with FLE 3 and doesn't add any value continue - } + } // Is it a Summit to Summit (sota) reference? workRef, sotaErr := ValidateSota(element) diff --git a/cmd/parse_line_test.go b/fleprocess/parse_line_test.go similarity index 99% rename from cmd/parse_line_test.go rename to fleprocess/parse_line_test.go index c7f7688..1901f07 100644 --- a/cmd/parse_line_test.go +++ b/fleprocess/parse_line_test.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess import ( "reflect" diff --git a/cmd/validate.go b/fleprocess/validate.go similarity index 99% rename from cmd/validate.go rename to fleprocess/validate.go index eca0e6f..c09371c 100644 --- a/cmd/validate.go +++ b/fleprocess/validate.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM diff --git a/cmd/validate_test.go b/fleprocess/validate_test.go similarity index 99% rename from cmd/validate_test.go rename to fleprocess/validate_test.go index 7b4cc3d..13c4d44 100644 --- a/cmd/validate_test.go +++ b/fleprocess/validate_test.go @@ -1,4 +1,4 @@ -package cmd +package fleprocess import ( "testing" @@ -276,8 +276,6 @@ func TestValidateDate(t *testing.T) { } } - - func TestIsBand(t *testing.T) { type args struct { inputStr string @@ -303,7 +301,7 @@ func TestIsBand(t *testing.T) { { "valid band but uppercase", args{inputStr: "40M"}, - true, 7.0, 7.3,"7MHz", + true, 7.0, 7.3, "7MHz", }, } for _, tt := range tests { diff --git a/main.go b/main.go index 15d307d..4a16614 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,10 @@ THE SOFTWARE. */ package main -import "FLEcli/cmd" +//import "github.com/spf13/cobra/cobra/cmd" + +import "FLEcli/flecmd" func main() { - cmd.Execute() + flecmd.Execute() } diff --git a/notes/generate_static_help.sh b/notes/generate_static_help.sh new file mode 100755 index 0000000..c96cfbb --- /dev/null +++ b/notes/generate_static_help.sh @@ -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 \ No newline at end of file