Simplify CLI user interface

pull/29/head v0.1.0
Jean-Marc MEESSEN 4 years ago committed by GitHub
parent 6134577dd0
commit 0b9fb5bc78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -7,6 +7,7 @@
FLEcli FLEcli
test/output/temp/* test/output/temp/*
dist/* dist/*
notes/help.txt
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

@ -18,7 +18,7 @@ builds:
- goos: windows - goos: windows
goarch: amd64 goarch: amd64
ldflags: 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: env:
- CGO_ENABLED=0 - CGO_ENABLED=0

@ -36,7 +36,7 @@ Most comon use cases are described hereafter as examples.
To load and validate the FLE formated file (`myActivation.txt`: 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. This command will parse and display the QSOs in grid format.
Fields that couldn't be successfully parsed are prefixed with "*". 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`: 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. The second element after the input specifies the path and name of the output file.
If the flag and value are omitted, the tool will generate a filename. If is omitted, the tool will generate a filename.
It is based on the input filename, just replacing the extension with `.adi`. 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 ### Example: generate an ADIF file for WWFF upload
To generate a WWFF-ready ADIF file: 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. The `--wwff` indicates the adif flavour to produce.
You can use the `--sota` switch to generate an ADIF file containing SOTA details. 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: 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. 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. If the output file exists, it will be overwritten as the `--overwrite` flag has been specified.

@ -8,4 +8,4 @@ commitRef=$(git rev-parse HEAD)
tag=$(git describe --tags) tag=$(git describe --tags)
version="${tag}_(PrivateBuild)" version="${tag}_(PrivateBuild)"
buildDate=$(date -u +"%FT%TZ") 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}"

@ -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)
}
}
}

@ -1,7 +1,10 @@
# Usage # Usage
## Overview ## Overview
``` ```
A Command Line "Fast Log Entry" (FLE) processor
Usage: Usage:
FLEcli [command] FLEcli [command]
@ -18,69 +21,62 @@ Flags:
Use "FLEcli [command] --help" for more information about a command. Use "FLEcli [command] --help" for more information about a command.
``` ```
## "LOAD" command ## "LOAD" command
``` ```
FLEcli load --help
Loads and validates a FLE type shorthand logfile Loads and validates a FLE type shorthand logfile
Usage: Usage:
FLEcli load [flags] FLEcli load [flags] inputFile
Flags: Flags:
-h, --help help for load -h, --help help for load
-i, --input string FLE formatted input file (mandatory) -i, --interpolate Interpolates the missing time entries.
--interpolate Interpolates the missing time entries.
Global Flags: Global Flags:
--config string config file (default is $HOME/.FLEcli.yaml) --config string config file (default is $HOME/.FLEcli.yaml)
``` ```
## "ADIF" command ## "ADIF" command
``` ```
FLEcli adif --help
Generates an ADIF file based on a FLE type shorthand logfile. Generates an ADIF file based on a FLE type shorthand logfile.
Usage: Usage:
FLEcli adif [flags] FLEcli adif [flags] inputFile [outputFile]
Flags: Flags:
-h, --help help for adif -h, --help help for adif
-i, --input string FLE formatted input file (mandatory) -i, --interpolate Interpolates the missing time entries.
--interpolate Interpolates the missing time entries. -o, --overwrite Overwrites the output file if it exisits
-o, --output string Output filename -s, --sota Generates a SOTA ready ADIF file.
--overwrite Overwrites the output file if it exisits -w, --wwff Generates a WWFF ready ADIF file.
-s, --sota Generates a SOTA ready ADIF file.
-w, --wwff Generates a WWFF ready ADIF file.
Global Flags: Global Flags:
--config string config file (default is $HOME/.FLEcli.yaml) --config string config file (default is $HOME/.FLEcli.yaml)
``` ```
## "CSV" command ## "CSV" command
``` ```
FLEcli csv --help
Generates a SOTA .csv file based on a FLE type shorthand logfile. Generates a SOTA .csv file based on a FLE type shorthand logfile.
Usage: Usage:
FLEcli csv [flags] FLEcli csv [flags] inputFile [outputFile]
Flags: Flags:
-h, --help help for csv -h, --help help for csv
-i, --input string FLE formatted input file (mandatory) -i, --interpolate Interpolates the missing time entries.
--interpolate Interpolates the missing time entries. -o, --overwrite Overwrites the output file if it exisits
-o, --output string Output filename
--overwrite Overwrites the output file if it exisits
Global Flags: Global Flags:
--config string config file (default is $HOME/.FLEcli.yaml) --config string config file (default is $HOME/.FLEcli.yaml)
``` ```
## "VERSION" command ## "VERSION" command
``` ```
FLEcli version --help
"version" will output the current build information "version" will output the current build information
Usage: Usage:
@ -93,4 +89,4 @@ Flags:
Global Flags: Global Flags:
--config string config file (default is $HOME/.FLEcli.yaml) --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. 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.

@ -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> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>

@ -1,4 +1,4 @@
package cmd package flecmd
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -24,16 +24,16 @@ THE SOFTWARE.
import ( import (
"fmt" "fmt"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"time"
) )
var ( var (
detailed = false detailed = false
version = "private build" version = "private build"
commit = "none" commit = "none"
date = "unknown" date = "unknown"
builtBy = "" builtBy = ""
versionCmd = &cobra.Command{ versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "\"version\" will output the current build information", Short: "\"version\" will output the current build information",

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -16,46 +16,20 @@ See the License for the specific language governing permissions and
limitations under the License. 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 ( import (
"fmt" "fmt"
"github.com/spf13/cobra"
) )
var outputCsvFilename string //ProcessCsvCommand loads an FLE input to produce a SOTA CSV
var isOverwriteCsv bool func ProcessCsvCommand(inputFilename, outputCsvFilename string, isInterpolateTime, 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() {
verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputCsvFilename, inputFilename, isOverwriteCsv, ".csv") verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputCsvFilename, inputFilename, isOverwriteCsv, ".csv")
// if the output file could not be parsed correctly do noting // if the output file could not be parsed correctly do noting
if filenameWasOK { if filenameWasOK {
loadedLogFile, isLoadedOK := loadFile() loadedLogFile, isLoadedOK := LoadFile(inputFilename, isInterpolateTime)
//TODO: move this in a function so that it can be more easily tested //TODO: move this in a function so that it can be more easily tested
if isLoadedOK { if isLoadedOK {

@ -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
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -24,8 +24,8 @@ import (
"time" "time"
) )
// outputAdif generates and writes data in ADIF format // OutputAdif generates and writes data in ADIF format
func outputAdif(outputFile string, fullLog []LogLine, isWWFF bool, isSOTA bool) { func OutputAdif(outputFile string, fullLog []LogLine, isWWFF bool, isSOTA bool) {
//convert the log data to an in-memory ADIF file //convert the log data to an in-memory ADIF file
adifData := buildAdif(fullLog, isWWFF, isSOTA) 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_SENT", logLine.RSTsent))
adifLine.WriteString(adifElement("RST_RCVD", logLine.RSTrcvd)) adifLine.WriteString(adifElement("RST_RCVD", logLine.RSTrcvd))
if logLine.Comment != "" { if logLine.Comment != "" {
adifLine.WriteString(adifElement("COMMENT", logLine.Comment)) adifLine.WriteString(adifElement("COMMENT", logLine.Comment))
} }
if logLine.OMname != "" { if logLine.OMname != "" {
adifLine.WriteString(adifElement("NAME", logLine.OMname)) adifLine.WriteString(adifElement("NAME", logLine.OMname))
} }
if logLine.QSLmsg != "" { if logLine.QSLmsg != "" {
adifLine.WriteString(adifElement("QSLMSG", logLine.QSLmsg)) adifLine.WriteString(adifElement("QSLMSG", logLine.QSLmsg))

@ -1,4 +1,4 @@
package cmd package fleprocess
import ( import (
"reflect" "reflect"

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>

@ -1,4 +1,4 @@
package cmd package fleprocess
import "testing" import "testing"

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -48,14 +48,14 @@ func buildCsv(fullLog []LogLine) (csvList []string) {
csvLine.WriteString(fmt.Sprintf(",%s", logLine.Time)) csvLine.WriteString(fmt.Sprintf(",%s", logLine.Time))
//TODO: Should we test the result //TODO: Should we test the result
_, _, _, sotaBand := IsBand(logLine.Band) _, _, _, sotaBand := IsBand(logLine.Band)
csvLine.WriteString(fmt.Sprintf(",%s",sotaBand )) csvLine.WriteString(fmt.Sprintf(",%s", sotaBand))
csvLine.WriteString(fmt.Sprintf(",%s",logLine.Mode)) csvLine.WriteString(fmt.Sprintf(",%s", logLine.Mode))
csvLine.WriteString(fmt.Sprintf(",%s", logLine.Call)) csvLine.WriteString(fmt.Sprintf(",%s", logLine.Call))
if logLine.SOTA != "" { if logLine.SOTA != "" {
csvLine.WriteString(fmt.Sprintf(",%s", logLine.SOTA)) csvLine.WriteString(fmt.Sprintf(",%s", logLine.SOTA))
} else { } else {
if logLine.Comment != "" { if logLine.Comment != "" {
csvLine.WriteString(",") csvLine.WriteString(",")
} }
} }
if logLine.Comment != "" { if logLine.Comment != "" {
@ -67,7 +67,6 @@ func buildCsv(fullLog []LogLine) (csvList []string) {
return csvList return csvList
} }
//adifDate converts a date in YYYY-MM-DD format to YYYYMMDD //adifDate converts a date in YYYY-MM-DD format to YYYYMMDD
func csvDate(inputDate string) (outputDate string) { func csvDate(inputDate string) (outputDate string) {
const FLEdateFormat = "2006-01-02" const FLEdateFormat = "2006-01-02"

@ -1,11 +1,11 @@
package cmd package fleprocess
import ( import (
"reflect" "reflect"
"testing" "testing"
) )
func Test_csvDate(t *testing.T) { func Test_csvDate(t *testing.T) {
type args struct { type args struct {
inputDate string inputDate string
} }

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>

@ -1,4 +1,4 @@
package cmd package fleprocess
import ( import (
"errors" "errors"

@ -1,4 +1,4 @@
package cmd package fleprocess
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -23,53 +23,11 @@ import (
"os" "os"
"regexp" "regexp"
"time" "time"
//"time"
"github.com/spf13/cobra"
//"strings"
) )
// loadCmd represents the load command //LoadFile FIXME
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")
}
//returns nill if failure to process //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) file, err := os.Open(inputFilename)
if err != nil { if err != nil {
@ -364,4 +322,4 @@ func displayLogSimple(fullLog []LogLine) {
fmt.Print(SprintLogInColumn(filledLogLine)) fmt.Print(SprintLogInColumn(filledLogLine))
} }
} }

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -17,16 +17,12 @@ limitations under the License.
*/ */
import ( import (
"os"
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
) )
// does the target file exist? //buildOutputFilname will try to figure out an output filename (for the case none was provided)
// is the file defined
// remove the extention
//returning "" is considered as invalid
func buildOutputFilename(output string, input string, overwrite bool, newExtension string) (outputFilename string, wasOK bool) { func buildOutputFilename(output string, input string, overwrite bool, newExtension string) (outputFilename string, wasOK bool) {
outputFilename = "" outputFilename = ""

@ -1,4 +1,4 @@
package cmd package fleprocess
import ( import (
"os" "os"

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -235,9 +235,9 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
// If the "sota" keyword is used, skip it // If the "sota" keyword is used, skip it
if regexpIsSotaKeyWord.MatchString(element) { 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 continue
} }
// Is it a Summit to Summit (sota) reference? // Is it a Summit to Summit (sota) reference?
workRef, sotaErr := ValidateSota(element) workRef, sotaErr := ValidateSota(element)

@ -1,4 +1,4 @@
package cmd package fleprocess
import ( import (
"reflect" "reflect"

@ -1,4 +1,4 @@
package cmd package fleprocess
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>

@ -1,4 +1,4 @@
package cmd package fleprocess
import ( import (
"testing" "testing"
@ -276,8 +276,6 @@ func TestValidateDate(t *testing.T) {
} }
} }
func TestIsBand(t *testing.T) { func TestIsBand(t *testing.T) {
type args struct { type args struct {
inputStr string inputStr string
@ -303,7 +301,7 @@ func TestIsBand(t *testing.T) {
{ {
"valid band but uppercase", "valid band but uppercase",
args{inputStr: "40M"}, args{inputStr: "40M"},
true, 7.0, 7.3,"7MHz", true, 7.0, 7.3, "7MHz",
}, },
} }
for _, tt := range tests { for _, tt := range tests {

@ -21,8 +21,10 @@ THE SOFTWARE.
*/ */
package main package main
import "FLEcli/cmd" //import "github.com/spf13/cobra/cobra/cmd"
import "FLEcli/flecmd"
func main() { func main() {
cmd.Execute() flecmd.Execute()
} }

@ -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…
Cancel
Save