Reformat the sources with go fmt

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 590988f3ad
commit ab925ad2dd

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

@ -1,4 +1,5 @@
package cmd
/*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -66,9 +67,9 @@ func SprintHeaderValues(logLine LogLine) (output string){
output = output + "MySOTA " + logLine.MySOTA + "\n"
}
return output
}
// Date, Time, band, mode, call, report sent, report rcvd, Notes
var logLineFormat = "%-10s %-4s %-4s %-4s %-10s %-4s %-4s %s \n"

@ -1,4 +1,5 @@
package cmd
/*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -16,9 +17,9 @@ limitations under the License.
*/
import (
"bufio"
"fmt"
"github.com/spf13/cobra"
"bufio"
"log"
"os"
"regexp"
@ -86,7 +87,6 @@ func loadFile() {
regexpHeaderNickname, _ := regexp.Compile("(?i)^nickname ")
regexpHeaderDate, _ := regexp.Compile("(?i)^date ")
headerMyCall := ""
headerOperator := ""
headerMyWWFF := ""
@ -103,7 +103,6 @@ func loadFile() {
var previousLogLine LogLine
var fullLog []LogLine
//Loop through all the stored lined
for _, eachline := range txtlines {
lineCount++
@ -113,25 +112,25 @@ func loadFile() {
// ****
//Skip the line if it starts with "#"
if(regexpLineComment.MatchString(eachline)) {
if regexpLineComment.MatchString(eachline) {
continue
}
//Skip if line is empty or blank
if((len(eachline) == 0) || (regexpOnlySpaces.MatchString(eachline))) {
if (len(eachline) == 0) || (regexpOnlySpaces.MatchString(eachline)) {
continue
}
// Process multi-line comments
if(regexpStartMultiLineComment.MatchString(eachline)) {
if regexpStartMultiLineComment.MatchString(eachline) {
//Single-line "multi-line" coment
if(regexpSingleMultiLineComment.MatchString(eachline)) {
if regexpSingleMultiLineComment.MatchString(eachline) {
continue
}
isInMultiLine = true
continue
}
if(isInMultiLine) {
if(regexpEndMultiLineComment.MatchString(eachline)) {
if isInMultiLine {
if regexpEndMultiLineComment.MatchString(eachline) {
isInMultiLine = false
}
continue
@ -142,13 +141,13 @@ func loadFile() {
// ****
//My Call
if(regexpHeaderMyCall.MatchString(eachline)) {
if regexpHeaderMyCall.MatchString(eachline) {
errorMsg := ""
myCallList := regexpHeaderMyCall.Split(eachline, -1)
if(len(myCallList[1]) > 0) {
if len(myCallList[1]) > 0 {
headerMyCall, errorMsg = ValidateCall(myCallList[1])
cleanedInput = append(cleanedInput, fmt.Sprintf("My call: %s", headerMyCall))
if(len(errorMsg) != 0) {
if len(errorMsg) != 0 {
errorLog = append(errorLog, fmt.Sprintf("Invalid myCall at line %d: %s (%s)", lineCount, myCallList[1], errorMsg))
}
}
@ -157,13 +156,13 @@ func loadFile() {
}
//Operator
if(regexpHeaderOperator.MatchString(eachline)) {
if regexpHeaderOperator.MatchString(eachline) {
errorMsg := ""
myOperatorList := regexpHeaderOperator.Split(eachline, -1)
if(len(myOperatorList[1]) > 0) {
if len(myOperatorList[1]) > 0 {
headerOperator, errorMsg = ValidateCall(myOperatorList[1])
cleanedInput = append(cleanedInput, fmt.Sprintf("Operator: %s", headerOperator))
if(len(errorMsg) != 0) {
if len(errorMsg) != 0 {
errorLog = append(errorLog, fmt.Sprintf("Invalid Operator at line %d: %s (%s)", lineCount, myOperatorList[1], errorMsg))
}
}
@ -172,13 +171,13 @@ func loadFile() {
}
// My WWFF
if(regexpHeaderMyWwff.MatchString(eachline)) {
if regexpHeaderMyWwff.MatchString(eachline) {
errorMsg := ""
myWwffList := regexpHeaderMyWwff.Split(eachline, -1)
if(len(myWwffList[1]) > 0) {
if len(myWwffList[1]) > 0 {
headerMyWWFF, errorMsg = ValidateWwff(myWwffList[1])
cleanedInput = append(cleanedInput, fmt.Sprintf("My WWFF: %s", headerMyWWFF))
if(len(errorMsg) != 0) {
if len(errorMsg) != 0 {
errorLog = append(errorLog, fmt.Sprintf("Invalid \"My WWFF\" at line %d: %s (%s)", lineCount, myWwffList[1], errorMsg))
}
}
@ -187,13 +186,13 @@ func loadFile() {
}
//My Sota
if(regexpHeaderMySota.MatchString(eachline)) {
if regexpHeaderMySota.MatchString(eachline) {
errorMsg := ""
mySotaList := regexpHeaderMySota.Split(eachline, -1)
if(len(mySotaList[1]) > 0) {
if len(mySotaList[1]) > 0 {
headerMySOTA, errorMsg = ValidateSota(mySotaList[1])
cleanedInput = append(cleanedInput, fmt.Sprintf("My Sota: %s", headerMySOTA))
if(len(errorMsg) != 0) {
if len(errorMsg) != 0 {
errorLog = append(errorLog, fmt.Sprintf("Invalid \"My SOTA\" at line %d: %s (%s)", lineCount, mySotaList[1], errorMsg))
}
}
@ -202,9 +201,9 @@ func loadFile() {
}
//QSL Message
if(regexpHeaderQslMsg.MatchString(eachline)) {
if regexpHeaderQslMsg.MatchString(eachline) {
myQslMsgList := regexpHeaderQslMsg.Split(eachline, -1)
if(len(myQslMsgList[1]) > 0) {
if len(myQslMsgList[1]) > 0 {
headerQslMsg = myQslMsgList[1]
cleanedInput = append(cleanedInput, fmt.Sprintf("QSL Message: %s", headerQslMsg))
}
@ -213,9 +212,9 @@ func loadFile() {
}
//Nickname
if(regexpHeaderNickname.MatchString(eachline)) {
if regexpHeaderNickname.MatchString(eachline) {
myNicknameList := regexpHeaderNickname.Split(eachline, -1)
if(len(myNicknameList[1]) > 0) {
if len(myNicknameList[1]) > 0 {
headerNickname = myNicknameList[1]
cleanedInput = append(cleanedInput, fmt.Sprintf("eQSL Nickmane: %s", headerNickname))
}
@ -224,12 +223,12 @@ func loadFile() {
}
// Date
if(regexpHeaderDate.MatchString(eachline)) {
if regexpHeaderDate.MatchString(eachline) {
errorMsg := ""
myDateList := regexpHeaderDate.Split(eachline, -1)
if(len(myDateList[1]) > 0) {
if len(myDateList[1]) > 0 {
headerDate, errorMsg = ValidateDate(myDateList[1])
if(len(errorMsg) != 0) {
if len(errorMsg) != 0 {
errorLog = append(errorLog, fmt.Sprintf("Invalid Date at line %d: %s (%s)", lineCount, myDateList[1], errorMsg))
}
}
@ -279,7 +278,7 @@ func loadFile() {
fmt.Print(SprintLogInColumn(filledLogLine))
}
if(len(errorLog) != 0){
if len(errorLog) != 0 {
fmt.Println("\nProcessing errors:")
for _, errorLogLine := range errorLog {
fmt.Println(errorLogLine)
@ -288,5 +287,4 @@ func loadFile() {
fmt.Println("\nSuccesfuly parsed ", lineCount, " lines.")
}
}

@ -1,4 +1,5 @@
package cmd
/*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -15,7 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import (
"fmt"
"regexp"
@ -26,7 +26,6 @@ import (
//TODO: validate a record for minimal values
// LogLine is used to store all the data of a single log line
type LogLine struct {
Date string
@ -95,7 +94,6 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
logLine.QSLmsg = QSLmsg
}
elements := strings.Fields(inputStr)
for _, element := range elements {
@ -172,14 +170,12 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
}
}
// Is it the OM's name (starting with "@")
if regexpIsOMname.MatchString(element) {
logLine.OMname = strings.TrimLeft(element, "@")
continue
}
// Is it the Grid Locator (starting with "#")
if regexpIsGridLoc.MatchString(element) {
logLine.GridLoc = strings.TrimLeft(element, "#")
@ -258,7 +254,6 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
return logLine, errorMsg
}
func lookupMode(lookup string) bool {
switch lookup {
case
@ -315,6 +310,3 @@ func lookupMode(lookup string) bool {
}
return false
}

@ -5,7 +5,6 @@ import (
"testing"
)
func TestParseLine(t *testing.T) {
type args struct {
inputStr string
@ -19,52 +18,52 @@ func TestParseLine(t *testing.T) {
}{
{
"Parse band and mode only",
args{ inputStr: "40M cw", previousLine: LogLine{ Mode: "SSB", }},
args{inputStr: "40M cw", previousLine: LogLine{Mode: "SSB"}},
LogLine{Band: "40m", BandLowerLimit: 7, BandUpperLimit: 7.3, Mode: "CW", ModeType: "CW", RSTsent: "599", RSTrcvd: "599"}, "",
},
{
"Parse for time",
args{ inputStr: "1314 g3noh", previousLine: LogLine{ Mode: "SSB", }},
args{inputStr: "1314 g3noh", previousLine: LogLine{Mode: "SSB"}},
LogLine{Time: "1314", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
},
{
"Parse partial time - 1",
args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "", Mode: "SSB", }},
args{inputStr: "4 g3noh", previousLine: LogLine{Time: "", Mode: "SSB"}},
LogLine{Time: "4", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "", //TODO: should fail
},
{
"Parse partial time - 2",
args{ inputStr: "15 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }},
args{inputStr: "15 g3noh", previousLine: LogLine{Time: "1200", Mode: "SSB"}},
LogLine{Time: "1215", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
},
{
"Parse partial time - 3",
args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }},
args{inputStr: "4 g3noh", previousLine: LogLine{Time: "1200", Mode: "SSB"}},
LogLine{Time: "1204", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
},
{
"Parse for comment",
args{ inputStr: "4 g3noh <PSE QSL Direct>", previousLine: LogLine{ Mode: "SSB", }},
args{inputStr: "4 g3noh <PSE QSL Direct>", previousLine: LogLine{Mode: "SSB"}},
LogLine{Time: "4", Comment: "PSE QSL Direct", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
},
{
"Parse for QSL",
args{ inputStr: "g3noh [Custom QSL message]", previousLine: LogLine{ Mode: "SSB", }},
args{inputStr: "g3noh [Custom QSL message]", previousLine: LogLine{Mode: "SSB"}},
LogLine{QSLmsg: "Custom QSL message", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
},
{
"Wrong mode",
args{ inputStr: "cww", previousLine: LogLine{ Mode: "SSB", }},
args{inputStr: "cww", previousLine: LogLine{Mode: "SSB"}},
LogLine{Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "Unable to parse cww ",
},
{
"Parse OM name",
args{ inputStr: "@Jean", previousLine: LogLine{ Mode: "SSB", }},
args{inputStr: "@Jean", previousLine: LogLine{Mode: "SSB"}},
LogLine{OMname: "Jean", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
},
{
"Parse Grid locator",
args{ inputStr: "#grid", previousLine: LogLine{ Mode: "SSB", }},
args{inputStr: "#grid", previousLine: LogLine{Mode: "SSB"}},
LogLine{GridLoc: "grid", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
},
{

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

@ -1,4 +1,5 @@
package cmd
/*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -16,13 +17,12 @@ limitations under the License.
*/
import (
"fmt"
"regexp"
"strings"
"fmt"
"time"
)
var validSotaRegexp = regexp.MustCompile(`^[0-9A-Z]{1,3}/[A-Z]{2}-[\d]{3}$`)
// ValidateSota verifies whether the supplied string is a valid SOTA reference.
@ -49,8 +49,6 @@ func ValidateWwff(inputStr string) (ref, errorMsg string) {
return wrongInputStr, "Invalid WWFF reference"
}
var validCallRegexp = regexp.MustCompile(`[\d]{0,1}[A-Z]{1,2}\d([A-Z]{1,4}|\d{3,3}|\d{1,3}[A-Z])[A-Z]{0,5}`)
var validPrefixRegexp = regexp.MustCompile(`\A\d?[a-zA-Z]{1,2}$`)
@ -181,7 +179,6 @@ func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float64) {
return false, 0, 0
}
func getDefaultReport(mode string) (modeType, defaultReport string) {
modeType = ""
defaultReport = ""

Loading…
Cancel
Save