func print256Colors() { ansi.DisableColors(false) stdout := os.Stdout bgColors := []string{""} for i := 0; i < 256; i++ { key := fmt.Sprintf(":%d", i) bgColors = append(bgColors, key) } keys := []string{} for fg := range ansi.Colors { n, err := strconv.Atoi(fg) if err == nil { keys = append(keys, fmt.Sprintf("%3d", n)) } } sort.Strings(keys) for _, fg := range keys { for _, bg := range bgColors { fmt.Fprintln(stdout, padColor(fg, []string{"" + bg, "+b" + bg, "+u" + bg})) fmt.Fprintln(stdout, padColor(fg, []string{"+B" + bg, "+Bb" + bg})) } } }
func printColors() { ansi.DisableColors(false) stdout := os.Stdout bgColors := []string{ "", ":black", ":red", ":green", ":yellow", ":blue", ":magenta", ":cyan", ":white", } keys := []string{} for fg := range ansi.Colors { _, err := strconv.Atoi(fg) if err != nil { keys = append(keys, fg) } } sort.Strings(keys) for _, fg := range keys { for _, bg := range bgColors { fmt.Fprintln(stdout, padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg})) fmt.Fprintln(stdout, padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"})) fmt.Fprintln(stdout, padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"})) } } }
func main() { log.SetFlags(0) args := os.Args[1:] if len(args) < 1 || strings.IndexRune(args[0], '-') == 0 { printUsageTo(os.Stderr) os.Exit(2) } // Perform updates as early as possible if args[0] == cmdUpdate.Name() { cmdUpdate.Run(cmdUpdate, args) return } else if updater != nil { defer updater.backgroundRun() } if !term.IsANSI(os.Stdout) { ansi.DisableColors(true) } for _, cmd := range commands { if cmd.Name() != args[0] || cmd.Run == nil { continue } defer recoverPanic() cmd.Flag.SetDisableDuplicates(true) // allow duplicate flag options cmd.Flag.Usage = func() { cmd.PrintUsage() } if cmd.NeedsServer { if exists, err := fileExists("server.yml"); err != nil || !exists { printFatal("server.yml not found - is this a server directory?") } } if err := cmd.Flag.Parse(args[1:]); err == flag.ErrHelp { cmdHelp.Run(cmdHelp, args[:1]) } else if err != nil { printError(err.Error()) os.Exit(2) } cmd.Run(cmd, cmd.Flag.Args()) return } fmt.Fprintf(os.Stderr, "Unknown command: %s\n", args[0]) if g := suggest(args[0]); len(g) > 0 { fmt.Fprintf(os.Stderr, "Possible alternatives: %v\n", strings.Join(g, " ")) } fmt.Fprintf(os.Stderr, "Run 'mc help' for usage.\n") os.Exit(2) }
func init() { ansi.DisableColors(false) cyan = ansi.ColorFunc("cyan") red = ansi.ColorFunc("red+b") yellow = ansi.ColorFunc("yellow+b") redInverse = ansi.ColorFunc("white:red") gray = ansi.ColorFunc("black+h") magenta = ansi.ColorFunc("magenta+h") writer = colorable.NewColorableStdout() }
func init() { if _, file, _, ok := runtime.Caller(0); ok { projectRootLength = len(file) - len("lib/ui/ui.go") } IsTerminal = terminal.IsTerminal(2) if !IsTerminal { ansi.DisableColors(true) } Init() }
func printPlain() { ansi.DisableColors(true) bgColors := []string{ "", ":black", ":red", ":green", ":yellow", ":blue", ":magenta", ":cyan", ":white", } for fg := range ansi.Colors { for _, bg := range bgColors { println(padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg})) println(padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"})) println(padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"})) } } }
func main() { honeybadger.ApiKey = "09d82034" if os.Getenv("CXENVIRONMENT") != "" { tokenFile = "cx_" + os.Getenv("CXENVIRONMENT") + ".json" honeybadger.Environment = os.Getenv("CXENVIRONMENT") } else { honeybadger.Environment = "production" } log.SetFlags(0) // make sure command is specified, disallow global args args := os.Args[1:] if len(args) < 1 || strings.IndexRune(args[0], '-') == 0 { printUsageTo(os.Stderr) os.Exit(2) } if args[0] == cmdUpdate.Name() { cmdUpdate.Run(cmdUpdate, args) return } else if VERSION != "dev" { defer backgroundRun() } if !term.IsANSI(os.Stdout) { ansi.DisableColors(true) } initClients() for _, cmd := range commands { if cmd.Name() == args[0] && cmd.Run != nil { defer recoverPanic() cmd.Flag.Usage = func() { cmd.printUsage() } if cmd.NeedsStack { cmd.Flag.StringVar(&flagStackName, "s", "", "stack name") } if err := cmd.Flag.Parse(args[1:]); err != nil { os.Exit(2) } if cmd.NeedsStack { s, err := stack() switch { case err == nil && s == nil: msg := "no stack specified" if err != nil { msg = err.Error() } printError(msg) cmd.printUsage() os.Exit(2) case err != nil: printFatal(err.Error()) } } cmd.Run(cmd, cmd.Flag.Args()) return } } // invalid command fmt.Fprintf(os.Stderr, "Unknown command: %s\n", args[0]) if g := suggest(args[0]); len(g) > 0 { fmt.Fprintf(os.Stderr, "Possible alternatives: %v\n", strings.Join(g, " ")) } fmt.Fprintf(os.Stderr, "Run 'cx help' for usage.\n") os.Exit(2) }
func main() { log.SetFlags(0) // make sure command is specified, disallow global args args := os.Args[1:] if len(args) < 1 || strings.IndexRune(args[0], '-') == 0 { printUsageTo(os.Stderr) os.Exit(2) } // Run the update command as early as possible to avoid the possibility of // installations being stranded without updates due to errors in other code if args[0] == cmdUpdate.Name() { cmdUpdate.Run(cmdUpdate, args) return } else if updater != nil { defer updater.backgroundRun() // doesn't run if os.Exit is called } if !term.IsANSI(os.Stdout) { ansi.DisableColors(true) } initClients() for _, cmd := range commands { if cmd.Name() == args[0] && cmd.Run != nil { defer recoverPanic() cmd.Flag.SetDisableDuplicates(true) // disallow duplicate flag options cmd.Flag.SetInterspersed(true) // allow flags & non-flag args to mix cmd.Flag.Usage = func() { cmd.printUsage() } if cmd.NeedsApp { cmd.Flag.StringVarP(&flagApp, "app", "a", "", "app name") } if err := cmd.Flag.Parse(args[1:]); err != nil { printError(err.Error()) os.Exit(2) } if flagApp != "" { if gitRemoteApp, err := appFromGitRemote(flagApp); err == nil { flagApp = gitRemoteApp } } if cmd.NeedsApp { a, err := app() switch { case err == errMultipleHerokuRemotes, err == nil && a == "": msg := "no app specified" if err != nil { msg = err.Error() } printError(msg) cmd.printUsage() os.Exit(2) case err != nil: printFatal(err.Error()) } } cmd.Run(cmd, cmd.Flag.Args()) return } } path := findPlugin(args[0]) if path == "" { fmt.Fprintf(os.Stderr, "Unknown command: %s\n", args[0]) if g := suggest(args[0]); len(g) > 0 { fmt.Fprintf(os.Stderr, "Possible alternatives: %v\n", strings.Join(g, " ")) } fmt.Fprintf(os.Stderr, "Run 'hk help' for usage.\n") os.Exit(2) } err := execPlugin(path, args) printFatal("exec error: %s", err) }
func main() { log.SetFlags(0) // make sure command is specified, disallow global args args := os.Args[1:] if len(args) < 1 || strings.IndexRune(args[0], '-') == 0 { printUsageTo(os.Stderr) os.Exit(2) } inFd, isTerminalIn = term.GetFdInfo(os.Stdin) outFd, isTerminalOut = term.GetFdInfo(os.Stdout) if !isTerminalOut { ansi.DisableColors(true) } initClients() for _, cmd := range commands { if matchesCommand(cmd, args[0]) && cmd.Run != nil { defer recoverPanic() cmd.Flag.SetDisableDuplicates(true) // disallow duplicate flag options if !gitConfigBool("hk.strict-flag-ordering") { cmd.Flag.SetInterspersed(true) // allow flags & non-flag args to mix } cmd.Flag.Usage = func() { cmd.PrintUsage() } if cmd.NeedsApp || cmd.OptionalApp { cmd.Flag.StringVarP(&flagApp, "app", "a", "", "app name") } if err := cmd.Flag.Parse(args[1:]); err == flag.ErrHelp { cmdHelp.Run(cmdHelp, args[:1]) return } else if err != nil { printError(err.Error()) os.Exit(2) } if flagApp != "" { if gitRemoteApp, err := appFromGitRemote(flagApp); err == nil { flagApp = gitRemoteApp } } if cmd.NeedsApp || cmd.OptionalApp { a, err := app() switch { case err == errMultipleHerokuRemotes && cmd.NeedsApp, err == nil && a == "" && cmd.NeedsApp: msg := "no app specified" if err != nil { msg = err.Error() } printError(msg) cmd.PrintUsage() os.Exit(2) case err != nil && cmd.NeedsApp: printFatal(err.Error()) } } cmd.Run(cmd, cmd.Flag.Args()) return } } fmt.Fprintf(os.Stderr, "Unknown command: %s\n", args[0]) if g := suggest(args[0]); len(g) > 0 { fmt.Fprintf(os.Stderr, "Possible alternatives: %v\n", strings.Join(g, " ")) } fmt.Fprintf(os.Stderr, "Run 'emp help' for usage.\n") os.Exit(2) }
func main() { log.SetFlags(0) // make sure command is specified, disallow global args args := os.Args[1:] if len(args) < 1 || strings.IndexRune(args[0], '-') == 0 { usage() } // Run the update command as early as possible to avoid the possibility of // installations being stranded without updates due to errors in other code if args[0] == cmdUpdate.Name() { cmdUpdate.Run(cmdUpdate, args) return } else if updater != nil { defer updater.backgroundRun() // doesn't run if os.Exit is called } if !term.IsTerminal(os.Stdout) { ansi.DisableColors(true) } initClients() for _, cmd := range commands { if cmd.Name() == args[0] && cmd.Run != nil { cmd.Flag.Usage = func() { cmd.printUsage() } if cmd.NeedsApp { cmd.Flag.StringVar(&flagApp, "a", "", "app name") } if err := cmd.Flag.Parse(args[1:]); err != nil { os.Exit(2) } if flagApp != "" { if gitRemoteApp, err := appFromGitRemote(flagApp); err == nil { flagApp = gitRemoteApp } } if cmd.NeedsApp { if a, _ := app(); a == "" { log.Println("no app specified") cmd.printUsage() os.Exit(2) } } cmd.Run(cmd, cmd.Flag.Args()) return } } path := findPlugin(args[0]) if path == "" { fmt.Fprintf(os.Stderr, "Unknown command: %s\n", args[0]) if g := suggest(args[0]); len(g) > 0 { fmt.Fprintf(os.Stderr, "Possible alternatives: %v\n", strings.Join(g, " ")) } fmt.Fprintf(os.Stderr, "Run 'hk help' for usage.\n") os.Exit(2) } err := execPlugin(path, args) printError("exec error: %s", err) }