//If MessageHelp was not called, the default summary for the command will be //printed. Otherwise, prints the string given to MessageHelp in its place func PrintMessage(command string, c *Command) { if messageToPrint == "" { messageToPrint = c.summary[command] } if len(messageArgs) > 0 { ansi.Fprintf(os.Stderr, messageToPrint, messageArgs...) } else { ansi.Fprintf(os.Stderr, messageToPrint) } ansi.Fprintf(os.Stderr, "\n") }
func PrintUsage(c string) { ansi.Fprintf(os.Stderr, "@G{shield %s}", c) sort.Sort(ByFlag(flagsToPrint)) for _, f := range flagsToPrint { if f.optional { ansi.Fprintf(os.Stderr, " @G{[%s]}", f.flag[0]) } else { ansi.Fprintf(os.Stderr, " @G{%s}", f.flag[0]) } } fmt.Fprintf(os.Stderr, "\n") }
func PrintInputHelp() { if inputHelpText == "" { return } Header("RAW INPUT") ansi.Fprintf(os.Stderr, "%s\n", PrettyJSON(inputHelpText)) }
func Confirm(prompt string) bool { in := bufio.NewReader(os.Stdin) for { ansi.Printf("@Y{%s [y/n]} ", prompt) v, err := in.ReadString('\n') if err != nil { ansi.Fprintf(os.Stderr, "failed: @R{%s}\n", err) return false } switch strings.TrimRight(v, "\n") { case "Y": fallthrough case "y": fallthrough case "yes": return true case "N": fallthrough case "n": fallthrough case "no": return false } } }
func printFlagHelper(flags []string, desc string, last bool) { defer func() { ansi.Fprintf(os.Stderr, "\n") }() //Print the flag list flagString := "@B{" + strings.Join(flags, "}, @B{") + "}" space := flagLen - len(strings.Join(flags, ", ")) + 2 lines := strings.Split(desc, "\n") for i, v := range lines { lines[i] = strings.Trim(v, " \t") } ansi.Fprintf(os.Stderr, " "+flagString+"%s%s", strings.Repeat(" ", space), lines[0]) if len(lines) <= 1 { return } for _, v := range lines[1:] { ansi.Fprintf(os.Stderr, "\n%s%s", strings.Repeat(" ", flagLen+4), v) } if len(lines) > 1 && !last { ansi.Fprintf(os.Stderr, "\n") } }
//Prints out all the aliases for the given command in the help format. func PrintAliasHelp(input string, c *Command) { aliases := c.AliasesFor(input) aliasString := "" if len(aliases) > 1 { aliasString = strings.Join(aliases, ", ") } if aliasString != "" { Header("ALIASES") ansi.Fprintf(os.Stderr, " %s\n", aliasString) } }
//Prints out a Header of the given string in the help format. func Header(text string) { ansi.Fprintf(os.Stderr, "\n@G{%s}\n", text) }
//Prints the JSON previously queued in the help format. func PrintJSONHelp() { if jsonToPrint != "" { Header("RAW OUTPUT") ansi.Fprintf(os.Stderr, "%s\n", PrettyJSON(jsonToPrint)) } }
func DisplayBackend(cfg *api.Config) { ansi.Fprintf(os.Stderr, "Using @G{%s} (%s) as SHIELD backend\n\n", cfg.BackendURI(), cfg.Backend) }