Skip to content

Commit 6b652ea

Browse files
authored
feature: provide a version sub-command
A version sub-command is implemented. A local install target is added to Makefile, to set version from git at build. Fixes #840.
1 parent 473bc63 commit 6b652ea

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal/cmd/extract/extract:
1616
generate: gen_all_syscall
1717
go generate
1818

19+
install:
20+
GOFLAGS=-ldflags=-X=main.version=$$(git describe --tags) go install ./...
21+
1922
tests:
2023
go test -v ./...
2124
go test -race ./interp
@@ -24,4 +27,4 @@ tests:
2427
install.sh: .goreleaser.yml
2528
godownloader --repo=traefik/yaegi -o install.sh .goreleaser.yml
2629

27-
.PHONY: check gen_all_syscall gen_tests generate_downloader internal/cmd/extract/extract
30+
.PHONY: check gen_all_syscall gen_tests generate_downloader internal/cmd/extract/extract install

cmd/yaegi/help.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The commands are:
1414
help print usage information
1515
run execute a Go program from source
1616
test execute test functions in a Go package
17+
version print version
1718
1819
Use "yaegi help <command>" for more information about a command.
1920
@@ -37,6 +38,9 @@ func help(arg []string) error {
3738
return run([]string{"-h"})
3839
case Test:
3940
return test([]string{"-h"})
41+
case Version:
42+
fmt.Println("Usage: yaegi version")
43+
return nil
4044
default:
4145
return fmt.Errorf("help: invalid yaegi command: %v", cmd)
4246
}

cmd/yaegi/yaegi.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ const (
106106
Help = "help"
107107
Run = "run"
108108
Test = "test"
109+
Version = "version"
109110
)
110111

112+
var version = "devel" // This may be overwritten at build time.
113+
111114
func main() {
112115
var cmd string
113116
var err error
@@ -128,6 +131,8 @@ func main() {
128131
err = run(os.Args[2:])
129132
case Test:
130133
err = test(os.Args[2:])
134+
case Version:
135+
fmt.Println(version)
131136
default:
132137
// If no command is given, fallback to default "run" command.
133138
// This allows scripts starting with "#!/usr/bin/env yaegi",

0 commit comments

Comments
 (0)