Add JSON output to info command (#2501)
main: Add json output flag to tinygo info
Этот коммит содержится в:
родитель
a888d6245d
коммит
84279ab2ec
1 изменённых файлов: 35 добавлений и 9 удалений
28
main.go
28
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -1193,8 +1194,10 @@ func main() {
|
||||||
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
|
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
|
||||||
|
|
||||||
var flagJSON, flagDeps, flagTest *bool
|
var flagJSON, flagDeps, flagTest *bool
|
||||||
if command == "help" || command == "list" {
|
if command == "help" || command == "list" || command == "info" {
|
||||||
flagJSON = flag.Bool("json", false, "print data in JSON format")
|
flagJSON = flag.Bool("json", false, "print data in JSON format")
|
||||||
|
}
|
||||||
|
if command == "help" || command == "list" {
|
||||||
flagDeps = flag.Bool("deps", false, "supply -deps flag to go list")
|
flagDeps = flag.Bool("deps", false, "supply -deps flag to go list")
|
||||||
flagTest = flag.Bool("test", false, "supply -test flag to go list")
|
flagTest = flag.Bool("test", false, "supply -test flag to go list")
|
||||||
}
|
}
|
||||||
|
@ -1509,6 +1512,28 @@ func main() {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
if *flagJSON {
|
||||||
|
json, _ := json.MarshalIndent(struct {
|
||||||
|
GOROOT string `json:"goroot"`
|
||||||
|
GOOS string `json:"goos"`
|
||||||
|
GOARCH string `json:"goarch"`
|
||||||
|
GOARM string `json:"goarm"`
|
||||||
|
BuildTags []string `json:"build_tags"`
|
||||||
|
GC string `json:"garbage_collector"`
|
||||||
|
Scheduler string `json:"scheduler"`
|
||||||
|
LLVMTriple string `json:"llvm_triple"`
|
||||||
|
}{
|
||||||
|
GOROOT: cachedGOROOT,
|
||||||
|
GOOS: config.GOOS(),
|
||||||
|
GOARCH: config.GOARCH(),
|
||||||
|
GOARM: config.GOARM(),
|
||||||
|
BuildTags: config.BuildTags(),
|
||||||
|
GC: config.GC(),
|
||||||
|
Scheduler: config.Scheduler(),
|
||||||
|
LLVMTriple: config.Triple(),
|
||||||
|
}, "", " ")
|
||||||
|
fmt.Println(string(json))
|
||||||
|
} else {
|
||||||
fmt.Printf("LLVM triple: %s\n", config.Triple())
|
fmt.Printf("LLVM triple: %s\n", config.Triple())
|
||||||
fmt.Printf("GOOS: %s\n", config.GOOS())
|
fmt.Printf("GOOS: %s\n", config.GOOS())
|
||||||
fmt.Printf("GOARCH: %s\n", config.GOARCH())
|
fmt.Printf("GOARCH: %s\n", config.GOARCH())
|
||||||
|
@ -1517,6 +1542,7 @@ func main() {
|
||||||
fmt.Printf("garbage collector: %s\n", config.GC())
|
fmt.Printf("garbage collector: %s\n", config.GC())
|
||||||
fmt.Printf("scheduler: %s\n", config.Scheduler())
|
fmt.Printf("scheduler: %s\n", config.Scheduler())
|
||||||
fmt.Printf("cached GOROOT: %s\n", cachedGOROOT)
|
fmt.Printf("cached GOROOT: %s\n", cachedGOROOT)
|
||||||
|
}
|
||||||
case "list":
|
case "list":
|
||||||
config, err := builder.NewConfig(options)
|
config, err := builder.NewConfig(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче