Add JSON output to info command (#2501)
main: Add json output flag to tinygo info
Этот коммит содержится в:
		
							родитель
							
								
									a888d6245d
								
							
						
					
					
						коммит
						84279ab2ec
					
				
					 1 изменённых файлов: 35 добавлений и 9 удалений
				
			
		
							
								
								
									
										44
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										44
									
								
								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,14 +1512,37 @@ func main() { | ||||||
| 			fmt.Fprintln(os.Stderr, err) | 			fmt.Fprintln(os.Stderr, err) | ||||||
| 			os.Exit(1) | 			os.Exit(1) | ||||||
| 		} | 		} | ||||||
| 		fmt.Printf("LLVM triple:       %s\n", config.Triple()) | 		if *flagJSON { | ||||||
| 		fmt.Printf("GOOS:              %s\n", config.GOOS()) | 			json, _ := json.MarshalIndent(struct { | ||||||
| 		fmt.Printf("GOARCH:            %s\n", config.GOARCH()) | 				GOROOT     string   `json:"goroot"` | ||||||
| 		fmt.Printf("GOARM:             %s\n", config.GOARM()) | 				GOOS       string   `json:"goos"` | ||||||
| 		fmt.Printf("build tags:        %s\n", strings.Join(config.BuildTags(), " ")) | 				GOARCH     string   `json:"goarch"` | ||||||
| 		fmt.Printf("garbage collector: %s\n", config.GC()) | 				GOARM      string   `json:"goarm"` | ||||||
| 		fmt.Printf("scheduler:         %s\n", config.Scheduler()) | 				BuildTags  []string `json:"build_tags"` | ||||||
| 		fmt.Printf("cached GOROOT:     %s\n", cachedGOROOT) | 				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("GOOS:              %s\n", config.GOOS()) | ||||||
|  | 			fmt.Printf("GOARCH:            %s\n", config.GOARCH()) | ||||||
|  | 			fmt.Printf("GOARM:             %s\n", config.GOARM()) | ||||||
|  | 			fmt.Printf("build tags:        %s\n", strings.Join(config.BuildTags(), " ")) | ||||||
|  | 			fmt.Printf("garbage collector: %s\n", config.GC()) | ||||||
|  | 			fmt.Printf("scheduler:         %s\n", config.Scheduler()) | ||||||
|  | 			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 { | ||||||
|  |  | ||||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Cameron Eagans
						Cameron Eagans