Skip to content

Commit e6cab6c

Browse files
aykevldeadprogram
authored andcommitted
main: add go env subcommand
This is required for integration in VS Code.
1 parent 2463153 commit e6cab6c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ func usage() {
720720
fmt.Fprintln(os.Stderr, " test: test packages")
721721
fmt.Fprintln(os.Stderr, " flash: compile and flash to the device")
722722
fmt.Fprintln(os.Stderr, " gdb: run/flash and immediately enter GDB")
723+
fmt.Fprintln(os.Stderr, " env: list environment variables used during build")
723724
fmt.Fprintln(os.Stderr, " clean: empty cache directory ("+goenv.Get("GOCACHE")+")")
724725
fmt.Fprintln(os.Stderr, " help: print this help text")
725726
fmt.Fprintln(os.Stderr, "\nflags:")
@@ -900,6 +901,18 @@ func main() {
900901
usage()
901902
case "version":
902903
fmt.Printf("tinygo version %s %s/%s\n", version, runtime.GOOS, runtime.GOARCH)
904+
case "env":
905+
if flag.NArg() == 0 {
906+
// Show all environment variables.
907+
for _, key := range goenv.Keys {
908+
fmt.Printf("%s=%#v\n", key, goenv.Get(key))
909+
}
910+
} else {
911+
// Show only one (or a few) environment variables.
912+
for i := 0; i < flag.NArg(); i++ {
913+
fmt.Println(goenv.Get(flag.Arg(i)))
914+
}
915+
}
903916
default:
904917
fmt.Fprintln(os.Stderr, "Unknown command:", command)
905918
usage()

0 commit comments

Comments
 (0)