Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coroc: print version on -v,--version #89

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions compiler/cmd/coroc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"runtime/debug"

"github.com/stealthrocket/coroutine/compiler"
)
Expand All @@ -15,9 +16,8 @@ USAGE:
coroc [OPTIONS] [PATH]

OPTIONS:
--output <FILENAME> Name of the Go file to generate in each package

-h, --help Show this help information
-h, --help Show this help information
-v, --version Show the compiler version
`

func main() {
Expand All @@ -29,8 +29,18 @@ func main() {

func run() error {
flag.Usage = func() { println(usage[1:]) }

var showVersion bool
flag.BoolVar(&showVersion, "v", false, "")
flag.BoolVar(&showVersion, "version", false, "")

flag.Parse()

if showVersion {
fmt.Println(version())
return nil
}

path := flag.Arg(0)
if path == "" {
// If the compiler was invoked via go generate, the GOFILE
Expand All @@ -47,3 +57,21 @@ func run() error {

return compiler.Compile(path)
}

func version() (version string) {
version = "devel"
if info, ok := debug.ReadBuildInfo(); ok {
switch info.Main.Version {
case "":
case "(devel)":
default:
version = info.Main.Version
}
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
version += " " + setting.Value
}
}
}
return
}