github.com/zxy12/go_duplicate_112_new@v0.0.0-20200807091221-747231827200/src/cmd/dist/main_func.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  )
     8  
     9  func usage() {
    10  	xprintf(`usage: go tool dist [command]
    11  Commands are:
    12  
    13  banner         print installation banner
    14  bootstrap      rebuild everything
    15  clean          deletes all built files
    16  env [-p]       print environment (-p: include $PATH)
    17  install [dir]  install individual directory
    18  list [-json]   list all supported platforms
    19  test [-h]      run Go test(s)
    20  version        print Go version
    21  
    22  All commands take -v flags to emit extra information.
    23  `)
    24  	xexit(2)
    25  }
    26  
    27  // The OS-specific main calls into the portable code here.
    28  func xmain() {
    29  	if len(os.Args) < 2 {
    30  		usage()
    31  	}
    32  	cmd := os.Args[1]
    33  	os.Args = os.Args[1:] // for flag parsing during cmd
    34  	flag.Usage = func() {
    35  		fmt.Fprintf(os.Stderr, "usage: go tool dist %s [options]\n", cmd)
    36  		flag.PrintDefaults()
    37  		os.Exit(2)
    38  	}
    39  	if f, ok := commands[cmd]; ok {
    40  		f()
    41  	} else {
    42  		xprintf("unknown command %s\n", cmd)
    43  		usage()
    44  	}
    45  }