diff --git a/adifmt/main.go b/adifmt/main.go index f75dd3e..1e6c253 100644 --- a/adifmt/main.go +++ b/adifmt/main.go @@ -108,6 +108,9 @@ func runMain(prepare func(l *adif.Logfile)) int { // filenames can come before or after flags, but not interspersed args := os.Args[2:] firstflag := slices.IndexFunc(args, func(s string) bool { return strings.HasPrefix(s, "-") }) + if firstflag < 0 { + firstflag = len(args) + } nonflags := args[0:firstflag] args = args[firstflag:] fs.Parse(args) diff --git a/adifmt/testdata/cat_flag_order.txtar b/adifmt/testdata/cat_flag_order.txtar index 58e1b00..25b4636 100644 --- a/adifmt/testdata/cat_flag_order.txtar +++ b/adifmt/testdata/cat_flag_order.txtar @@ -28,6 +28,28 @@ exec adifmt cat --output json --json-indent 2 -- -with-hyphen.tsv bar.tsv cmp stdout combined.json ! stderr . +# No flags +exec adifmt cat foo.tsv bar.tsv +cmp stdout combined.adi +! stderr . + +# Single file, no flags +exec adifmt cat bar.tsv +cmp stdout bar.adi +! stderr . + +# Pipe input, no flags +stdin bar.tsv +exec adifmt cat +cmp stdout bar.adi +! stderr . + +# Pipe input, change format +stdin bar.tsv +exec adifmt cat --output adx +cmp stdout bar.adx +! stderr . + -- foo.tsv -- CALL MODE K1A CW @@ -63,3 +85,36 @@ W4D RTTY } ] } +-- combined.adi -- +Generated with 4 records by https://github.com/flwyd/adif-multitool +3.1.4 23450607 080910 adifmt (devel) +K1A CW +W2B SSB +K3C FM +W4D RTTY +-- bar.adi -- +Generated with 2 records by https://github.com/flwyd/adif-multitool +3.1.4 23450607 080910 adifmt (devel) +K3C FM +W4D RTTY +-- bar.adx -- + + +
+ + 3.1.4 + 23450607 080910 + adifmt + (devel) +
+ + + K3C + FM + + + W4D + RTTY + + +
diff --git a/adifmt/testdata/version.txtar b/adifmt/testdata/version.txtar new file mode 100644 index 0000000..5c59608 --- /dev/null +++ b/adifmt/testdata/version.txtar @@ -0,0 +1,11 @@ +# Tests the version command. + +exec adifmt version +cmp stdout expected.txt +! stderr . + +-- expected.txt -- +adifmt version (devel) +Built from git revision (unknown) +ADIF version 3.1.4 from https://adif.org/314/ADIF_314.htm +See https://github.com/flwyd/adif-multitool for details