1
1
mirror of https://github.com/wader/fq.git synced 2024-11-27 06:04:47 +03:00

fq: Add arch and os to --version

This commit is contained in:
Mattias Wadman 2022-01-26 18:09:59 +01:00
parent 5bf83764b2
commit 233d86a384
6 changed files with 13 additions and 9 deletions

4
fq.go
View File

@ -1,6 +1,8 @@
package main
import (
"runtime"
_ "github.com/wader/fq/format/all"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/cli"
@ -9,5 +11,5 @@ import (
const version = "0.0.4"
func main() {
cli.Main(registry.Default, version)
cli.Main(registry.Default, version, runtime.GOOS, runtime.GOARCH)
}

View File

@ -224,7 +224,7 @@ func (o *stdOS) Close() error {
return nil
}
func Main(r *registry.Registry, version string) {
func Main(r *registry.Registry, version string, osStr string, archStr string) {
os.Exit(func() int {
defer maybeProfile()()
maybeLogFile()
@ -238,7 +238,7 @@ func Main(r *registry.Registry, version string) {
return 1
}
if err := i.Main(context.Background(), sos.Stdout(), version); err != nil {
if err := i.Main(context.Background(), sos.Stdout(), version, osStr, archStr); err != nil {
if ex, ok := err.(interp.Exiter); ok { //nolint:errorlint
return ex.ExitCode()
}

View File

@ -41,7 +41,7 @@ func TestPath(t *testing.T, registry *registry.Registry) {
t.Fatal(err)
}
err = i.Main(context.Background(), cr.Stdout(), "dev")
err = i.Main(context.Background(), cr.Stdout(), "testversion", "testos", "testarch")
if err != nil {
if ex, ok := err.(interp.Exiter); ok { //nolint:errorlint
cr.ActualExitCode = ex.ExitCode()

View File

@ -359,7 +359,7 @@ func (i *Interp) Stop() {
i.interruptStack.Stop()
}
func (i *Interp) Main(ctx context.Context, output Output, version string) error {
func (i *Interp) Main(ctx context.Context, output Output, versionStr string, osStr string, archStr string) error {
var args []interface{}
for _, a := range i.os.Args() {
args = append(args, a)
@ -367,7 +367,9 @@ func (i *Interp) Main(ctx context.Context, output Output, version string) error
input := map[string]interface{}{
"args": args,
"version": version,
"version": versionStr,
"os": osStr,
"arch": archStr,
}
iter, err := i.EvalFunc(ctx, input, "_main", nil, output)

View File

@ -180,7 +180,7 @@ def _main:
);
def _usage($arg0):
"Usage: \($arg0) [OPTIONS] [--] [EXPR] [FILE...]";
( . as {$version, $args, args: [$arg0]}
( . as {$version, $os, $arch, $args, args: [$arg0]}
# make sure we don't unintentionally use . to make things clearer
| null
| ( try _args_parse($args[1:]; _opt_cli_opts)
@ -303,7 +303,7 @@ def _main:
, args_help_text(_opt_cli_opts)
) | println
elif $opts.show_version then
$version | println
"\($version) (\($os) \($arch))" | println
elif $opts.show_formats then
_formats_list | println
elif

View File

@ -1,2 +1,2 @@
$ fq -v
dev
testversion (testos testarch)