Skip to content

Commit

Permalink
cli: Add go version to version string
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Aug 20, 2024
1 parent 5766566 commit 550bcc2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions internal/script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/interp/init.jq
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions pkg/interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/testdata/version.fqtest
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$ fq -v
testversion (testos testarch)
testversion (testos testarch testgo_version)

0 comments on commit 550bcc2

Please sign in to comment.