From 0e1cbd8bd01237a81c00fd9aeb77dca74417d40a Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Mon, 26 Feb 2024 16:29:27 +0000 Subject: [PATCH] embed version info in KML/Z description --- cmd/flightlog2kml/main.go | 10 +++++----- cmd/mission2kml/main.go | 19 +++++++++++++------ pkg/kmlgen/kmlbuilder.go | 15 +++++++++------ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/cmd/flightlog2kml/main.go b/cmd/flightlog2kml/main.go index f47294d..0a2913b 100644 --- a/cmd/flightlog2kml/main.go +++ b/cmd/flightlog2kml/main.go @@ -23,21 +23,21 @@ import ( var GitCommit = "local" var GitTag = "0.0.0" -func getVersion() string { +func GetVersion() string { return fmt.Sprintf("%s %s commit:%s", filepath.Base(os.Args[0]), GitTag, GitCommit) } func main() { dump_log := os.Getenv("DUMP_LOG") != "" - files, _ := options.ParseCLI(getVersion) + files, _ := options.ParseCLI(GetVersion) if len(files) == 0 { if len(options.Config.Mission) > 0 { outms := kmlgen.GenKmlName(options.Config.Mission, options.Config.MissionIndex) - kmlgen.GenerateMissionOnly(outms) + kmlgen.GenerateMissionOnly(outms, GetVersion) show_output(outms) } else if len(options.Config.Cli) > 0 { outms := kmlgen.GenKmlName(options.Config.Cli, 0) - kmlgen.GenerateCliOnly(outms) + kmlgen.GenerateCliOnly(outms, GetVersion) show_output(outms) } else { options.Usage() @@ -93,7 +93,7 @@ func main() { } } else if options.Config.Summary == false { outfn = kmlgen.GenKmlName(b.Logname, b.Index) - kmlgen.GenerateKML(ls.H, ls.L, outfn, b, ls.M) + kmlgen.GenerateKML(ls.H, ls.L, outfn, b, ls.M, GetVersion) } } for k, v := range ls.M { diff --git a/cmd/mission2kml/main.go b/cmd/mission2kml/main.go index fc2f1c3..5f9028b 100644 --- a/cmd/mission2kml/main.go +++ b/cmd/mission2kml/main.go @@ -32,7 +32,7 @@ var ( outfile string ) -func getVersion() string { +func GetVersion() string { return fmt.Sprintf("%s %s commit:%s", filepath.Base(os.Args[0]), GitTag, GitCommit) } @@ -72,7 +72,7 @@ Examples: flag.PrintDefaults() fmt.Fprintln(os.Stderr) fmt.Fprintln(os.Stderr, extra) - fmt.Fprintln(os.Stderr, getVersion()) + fmt.Fprintln(os.Stderr, GetVersion()) } defs := os.Getenv("BBL2KML_OPTS") @@ -140,13 +140,20 @@ Examples: } func generateKML(mfile string, idx int, dms bool, homep []float64, clifile string) error { - var kname string + var sb strings.Builder + kname := "" + sb.Write([]byte(fmt.Sprintf("Generator: %s", GetVersion()))) if mfile != "" { + sb.Write([]byte(fmt.Sprintf(" mission: %s", filepath.Base(mfile)))) kname = filepath.Base(mfile) - } else { - kname = filepath.Base(clifile) } - d := kml.Folder(kml.Name(kname)).Add(kml.Description(kname)).Add(kml.Open(true)) + if clifile != "" { + sb.Write([]byte(fmt.Sprintf(" cli: %s", filepath.Base(clifile)))) + if mfile == "" { + kname = filepath.Base(clifile) + } + } + d := kml.Folder(kml.Name(kname)).Add(kml.Description(sb.String())).Add(kml.Open(true)) k := kml.KML(d) var err error diff --git a/pkg/kmlgen/kmlbuilder.go b/pkg/kmlgen/kmlbuilder.go index 1f7b9a6..b4c6744 100644 --- a/pkg/kmlgen/kmlbuilder.go +++ b/pkg/kmlgen/kmlbuilder.go @@ -479,9 +479,10 @@ func add_ground_track(rec types.LogRec) kml.Element { return f } -func GenerateCliOnly(outfn string) { +func GenerateCliOnly(outfn string, gv func() string) { kname := filepath.Base(options.Config.Cli) - d := kml.Folder(kml.Name(kname)).Add(kml.Open(true)) + desc := fmt.Sprintf("Generator: %s", gv()) + d := kml.Folder(kml.Name(kname)).Add(kml.Description(desc)).Add(kml.Open(true)) sfx := Generate_cli_kml(options.Config.Cli) for _, s := range sfx { d.Add(s) @@ -489,9 +490,10 @@ func GenerateCliOnly(outfn string) { write_kml(outfn, d) } -func GenerateMissionOnly(outfn string) { +func GenerateMissionOnly(outfn string, gv func() string) { kname := filepath.Base(options.Config.Mission) - d := kml.Folder(kml.Name(kname)).Add(kml.Open(true)) + desc := fmt.Sprintf("Generator: %s", gv()) + d := kml.Folder(kml.Name(kname)).Add(kml.Description(desc)).Add(kml.Open(true)) _, mm, err := mission.Read_Mission_File(options.Config.Mission) if err == nil { isviz := true @@ -529,7 +531,7 @@ func GenerateMissionOnly(outfn string) { } func GenerateKML(hpos types.HomeRec, rec types.LogRec, outfn string, - meta types.FlightMeta, smap types.MapRec) { + meta types.FlightMeta, smap types.MapRec, gv func() string) { defviz := !(options.Config.Rssi && rec.Items[0].Rssi > 0) ts0 := rec.Items[0].Utc @@ -539,7 +541,8 @@ func GenerateKML(hpos types.HomeRec, rec types.LogRec, outfn string, Add(generate_shared_styles(0)...). Add(getPoints(rec, hpos, COL_STYLE_MODE, defviz)...) - d := kml.Folder(kml.Name(meta.LogName())).Add(kml.Open(true)) + desc := fmt.Sprintf("Generator: %s", gv()) + d := kml.Folder(kml.Name(meta.LogName())).Add(kml.Description(desc)).Add(kml.Open(true)) d.Add(add_ground_track(rec)) if len(options.Config.Mission) > 0 {