re-use adif_filename to build .csv

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 0716f4565a
commit b3c169228f

@ -1,4 +1,4 @@
package cmd package cmd
//VersionString is the version that will be displayed with the -v switch //VersionString is the version that will be displayed with the -v switch
const VersionString = "v0.0.0.0-3-gefb75a4 (2020-07-13)" const VersionString = "v0.0.0.0-4-g0716f45 (2020-07-13)"

@ -51,7 +51,7 @@ func init() {
func processAdifCommand() { func processAdifCommand() {
verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputFilename, inputFilename, isOverwrite) verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputFilename, inputFilename, isOverwrite, ".adi")
fmt.Println("adif called") fmt.Println("adif called")
fmt.Println("Inputfile: ", inputFilename) fmt.Println("Inputfile: ", inputFilename)
fmt.Println("OutputFile: ", outputFilename) fmt.Println("OutputFile: ", outputFilename)

@ -47,13 +47,13 @@ func init() {
func processCsvCommand() { func processCsvCommand() {
verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputFilename, inputFilename, isOverwrite) verifiedOutputFilename, filenameWasOK := buildOutputFilename(outputCsvFilename, inputFilename, isOverwrite, ".csv")
fmt.Println("csv called") fmt.Println("csv called")
fmt.Println("Inputfile: ", inputFilename) fmt.Println("Inputfile: ", inputFilename)
fmt.Println("OutputFile: ", outputFilename) fmt.Println("OutputFile: ", outputFilename)
fmt.Println("computed output: ", verifiedOutputFilename) fmt.Println("computed output: ", verifiedOutputFilename)
fmt.Println("Output filenameWasOK: ", filenameWasOK) fmt.Println("Output filenameWasOK: ", filenameWasOK)
fmt.Println("isOverwrite: ", isOverwrite) fmt.Println("isOverwriteCsv: ", isOverwriteCsv)
// 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 {

@ -18,7 +18,6 @@ limitations under the License.
import ( import (
"os" "os"
//"log"
"fmt" "fmt"
"path/filepath" "path/filepath"
) )
@ -28,7 +27,7 @@ import (
// remove the extention // remove the extention
//returning "" is considered as invalid //returning "" is considered as invalid
func buildOutputFilename(output string, input string, overwrite bool) (outputFilename string, wasOK bool) { func buildOutputFilename(output string, input string, overwrite bool, newExtension string) (outputFilename string, wasOK bool) {
outputFilename = "" outputFilename = ""
//validate that input is populated (should never happen if properly called) //validate that input is populated (should never happen if properly called)
@ -40,7 +39,7 @@ func buildOutputFilename(output string, input string, overwrite bool) (outputFil
if output == "" { if output == "" {
extension := filepath.Ext(input) extension := filepath.Ext(input)
outputRootPart := input[0 : len(input)-len(extension)] outputRootPart := input[0 : len(input)-len(extension)]
output = outputRootPart + ".adi" output = outputRootPart + newExtension
fmt.Println("No output provided, defaulting to \"" + output + "\"") fmt.Println("No output provided, defaulting to \"" + output + "\"")
} }

@ -30,6 +30,7 @@ func Test_buildOutputFilename(t *testing.T) {
output string output string
input string input string
overwrite bool overwrite bool
extension string
} }
tests := []struct { tests := []struct {
name string name string
@ -39,37 +40,37 @@ func Test_buildOutputFilename(t *testing.T) {
}{ }{
{ {
"input file not provided", "input file not provided",
args{input: "", output: "xxx", overwrite: false}, args{input: "", output: "xxx", overwrite: false, extension: ".adi"},
"", false, "", false,
}, },
{ {
"Output file does not exist", "Output file does not exist",
args{input: "a file", output: "output.adi", overwrite: false}, args{input: "a file", output: "output.adi", overwrite: false, extension: ".adi"},
"output.adi", true, "output.adi", true,
}, },
{ {
"Output name is a directory", "Output name is a directory",
args{input: "a file", output: testDir, overwrite: false}, args{input: "a file", output: testDir, overwrite: false, extension: ".adi"},
"", false, "", false,
}, },
{ {
"Output exist but no overwrite", "Output exist but no overwrite",
args{input: "a file", output: testFile, overwrite: false}, args{input: "a file", output: testFile, overwrite: false, extension: ".adi"},
"", false, "", false,
}, },
{ {
"no output, input provided with extention", "no output, input provided with extention",
args{input: "/test/data/file.txt", output: "", overwrite: false}, args{input: "/test/data/file.txt", output: "", overwrite: false, extension: ".adi"},
"/test/data/file.adi", true, "/test/data/file.adi", true,
}, },
{ {
"no output, input provided without extention", "no output, input provided without extention",
args{input: "/test/data/file", output: "", overwrite: false}, args{input: "/test/data/file", output: "", overwrite: false, extension: ".adi"},
"/test/data/file.adi", true, "/test/data/file.adi", true,
}, },
{ {
"no output, input provided, enfing with a point", "no output, input provided, enfing with a point",
args{input: "/test/data/file.", output: "", overwrite: false}, args{input: "/test/data/file.", output: "", overwrite: false, extension: ".adi"},
"/test/data/file.adi", true, "/test/data/file.adi", true,
}, },
} }
@ -79,7 +80,7 @@ func Test_buildOutputFilename(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
gotOutputFilename, gotWasOK := buildOutputFilename(tt.args.output, tt.args.input, tt.args.overwrite) gotOutputFilename, gotWasOK := buildOutputFilename(tt.args.output, tt.args.input, tt.args.overwrite, tt.args.extension)
if gotOutputFilename != tt.wantOutputFilename { if gotOutputFilename != tt.wantOutputFilename {
t.Errorf("buildOutputFilename() gotOutputFilename = %v, want %v", gotOutputFilename, tt.wantOutputFilename) t.Errorf("buildOutputFilename() gotOutputFilename = %v, want %v", gotOutputFilename, tt.wantOutputFilename)
} }
Loading…
Cancel
Save