1
0
Fork 0
mirror of https://github.com/on4kjm/FLEcli.git synced 2025-02-17 04:22:36 +01:00
FLEcli/cmd/adif.go

90 lines
2.6 KiB
Go
Raw Normal View History

2020-06-27 13:57:59 +02:00
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"
2020-06-27 22:53:23 +02:00
// "log"
2020-06-27 13:57:59 +02:00
//"strings"
)
2020-06-28 14:52:24 +02:00
var outputFilename string
2020-07-12 22:33:01 +02:00
var isWWFFcli bool
var isSOTAcli bool
var isOverwrite bool
2020-06-28 14:52:24 +02:00
2020-06-27 13:57:59 +02:00
// 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) {
2020-06-28 14:52:24 +02:00
processAdifCommand()
2020-06-27 13:57:59 +02:00
},
}
func init() {
rootCmd.AddCommand(adifCmd)
2020-07-12 22:33:01 +02:00
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.")
2020-06-29 13:55:11 +02:00
adifCmd.PersistentFlags().BoolVarP(&isOverwrite, "overwrite", "", false, "Overwrites the output file if it exisits")
2020-06-28 14:52:24 +02:00
adifCmd.PersistentFlags().StringVarP(&outputFilename, "output", "o", "", "Output filename")
2020-06-27 13:57:59 +02:00
}
2020-06-28 14:52:24 +02:00
2020-06-29 13:55:11 +02:00
func processAdifCommand() {
2020-07-13 21:25:06 +02:00
verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputFilename, inputFilename, isOverwrite, ".adi")
2020-06-29 13:55:11 +02:00
// if the output file could not be parsed correctly do noting
2020-06-30 22:20:56 +02:00
if filenameWasOK {
2020-06-29 13:55:11 +02:00
loadedLogFile, isLoadedOK := loadFile()
2020-06-30 22:20:56 +02:00
//TODO: move this in a function so that it can be more easily tested
2020-06-29 13:55:11 +02:00
if isLoadedOK {
2020-06-30 22:20:56 +02:00
if len(loadedLogFile) == 0 {
fmt.Println("No useful data read. Aborting...")
return
}
2020-07-12 22:33:01 +02:00
//TODO: There are more tests required here
2020-06-29 13:55:11 +02:00
//check if we have the necessary information for the type
2020-07-12 22:33:01 +02:00
if isWWFFcli {
2020-06-30 22:20:56 +02:00
if loadedLogFile[0].MyWWFF == "" {
fmt.Println("Missing MY-WWFF reference. Aborting...")
return
}
2020-07-16 20:14:52 +02:00
if loadedLogFile[0].Operator == "" {
fmt.Println("Missing Operator. Aborting...")
return
}
2020-06-30 22:20:56 +02:00
}
2020-07-14 21:39:31 +02:00
if isSOTAcli {
if loadedLogFile[0].MySOTA == "" {
fmt.Println("Missing MY-SOTA reference. Aborting...")
return
}
}
2020-06-29 13:55:11 +02:00
2020-07-12 22:33:01 +02:00
outputAdif(verifiedOutputFilename, loadedLogFile, isWWFFcli, isSOTAcli)
2020-06-29 13:55:11 +02:00
}
}
}