github.com/mem/u-root@v2.0.1-0.20181004165302-9b18b4636a33+incompatible/cmds/elvish/program/subprograms.go (about) 1 package program 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/u-root/u-root/cmds/elvish/build" 8 ) 9 10 // ShowHelp shows help message. 11 type ShowHelp struct { 12 flag *flagSet 13 } 14 15 func (s ShowHelp) Main([]string) int { 16 usage(os.Stdout, s.flag) 17 return 0 18 } 19 20 type ShowCorrectUsage struct { 21 message string 22 flag *flagSet 23 } 24 25 func (s ShowCorrectUsage) Main([]string) int { 26 usage(os.Stderr, s.flag) 27 return 2 28 } 29 30 // ShowVersion shows the version. 31 type ShowVersion struct{} 32 33 func (ShowVersion) Main([]string) int { 34 fmt.Println(build.Version) 35 fmt.Fprintln(os.Stderr, "-version is deprecated and will be removed in 0.12. Use -buildinfo instead.") 36 return 0 37 } 38 39 // ShowBuildInfo shows build information. 40 type ShowBuildInfo struct { 41 JSON bool 42 } 43 44 func (info ShowBuildInfo) Main([]string) int { 45 if info.JSON { 46 fmt.Printf("{version: %s, builder: %s}\n", 47 quoteJSON(build.Version), quoteJSON(build.Builder)) 48 } else { 49 fmt.Println("version:", build.Version) 50 fmt.Println("builder:", build.Builder) 51 } 52 return 0 53 }