From 550bcc27ff7c617e174f25319635a70e2ad7b700 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Tue, 20 Aug 2024 13:30:40 +0200 Subject: [PATCH] cli: Add go version to version string --- internal/script/script.go | 5 +++-- pkg/cli/cli.go | 5 +++-- pkg/interp/init.jq | 4 ++-- pkg/interp/interp.go | 14 ++++++++------ pkg/interp/testdata/version.fqtest | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/internal/script/script.go b/internal/script/script.go index d3a67fb5..cca19dcf 100644 --- a/internal/script/script.go +++ b/internal/script/script.go @@ -118,8 +118,9 @@ func (cr *CaseRun) getEnvInt(name string) int { func (cr *CaseRun) Platform() interp.Platform { return interp.Platform{ - OS: "testos", - Arch: "testarch", + OS: "testos", + Arch: "testarch", + GoVersion: "testgo_version", } } diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index a63bebd3..d1b9a49f 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -81,8 +81,9 @@ func newStandardOS() *stdOS { func (stdOS) Platform() interp.Platform { return interp.Platform{ - OS: runtime.GOOS, - Arch: runtime.GOARCH, + OS: runtime.GOOS, + Arch: runtime.GOARCH, + GoVersion: runtime.Version(), } } diff --git a/pkg/interp/init.jq b/pkg/interp/init.jq index 83786a76..e54a8180 100644 --- a/pkg/interp/init.jq +++ b/pkg/interp/init.jq @@ -168,7 +168,7 @@ def _main: ) ) ); - ( . as {$version, $os, $arch, $args, args: [$arg0]} + ( . as {$version, $os, $arch, $go_version, $args, args: [$arg0]} # make sure we don't unintentionally use . to make things clearer | null | ( try _args_parse($args[1:]; _opt_cli_opts) @@ -203,7 +203,7 @@ def _main: | println ) elif $opts.show_version then - "\($version) (\($os) \($arch))" | println + "\($version) (\($os) \($arch) \($go_version))" | println elif ( $opts.filenames == [null] and $opts.null_input == false and diff --git a/pkg/interp/interp.go b/pkg/interp/interp.go index 22affe61..43d0cf4d 100644 --- a/pkg/interp/interp.go +++ b/pkg/interp/interp.go @@ -131,8 +131,9 @@ type Output interface { } type Platform struct { - OS string - Arch string + OS string + Arch string + GoVersion string } type CompleteFn func(line string, pos int) (newLine []string, shared int) @@ -380,10 +381,11 @@ func (i *Interp) Main(ctx context.Context, output Output, versionStr string) err platform := i.OS.Platform() input := map[string]any{ - "args": args, - "version": versionStr, - "os": platform.OS, - "arch": platform.Arch, + "args": args, + "version": versionStr, + "os": platform.OS, + "arch": platform.Arch, + "go_version": platform.GoVersion, } iter, err := i.EvalFunc(ctx, input, "_main", nil, EvalOpts{output: output}) diff --git a/pkg/interp/testdata/version.fqtest b/pkg/interp/testdata/version.fqtest index 8ef08428..50a71baa 100644 --- a/pkg/interp/testdata/version.fqtest +++ b/pkg/interp/testdata/version.fqtest @@ -1,2 +1,2 @@ $ fq -v -testversion (testos testarch) +testversion (testos testarch testgo_version)