func summary(colour bool) { text := "TMSU" if colour { text = ansi.Bold(text) } fmt.Println(text) fmt.Println() var maxWidth int for _, command := range helpCommands { maxWidth = int(math.Max(float64(maxWidth), float64(len(command.Name)))) } for _, command := range helpCommands { if command.Hidden && log.Verbosity < 2 { continue } synopsis := command.Synopsis if !colour { synopsis = ansi.Strip(synopsis) } line := fmt.Sprintf(" %-*v %v", maxWidth, command.Name, synopsis) if command.Hidden && colour { line = ansi.Yellow(line) } terminal.PrintWrapped(line) } fmt.Println() text = "Global options:" if colour { text = ansi.Bold(text) } fmt.Println(text) fmt.Println() printOptions(globalOptions) fmt.Println() terminal.PrintWrapped("Specify subcommand name for detailed help on a particular subcommand, e.g. tmsu help files") }
func describeCommand(commandName string, colour bool) { command := findCommand(helpCommands, commandName) if command == nil { fmt.Printf("No such command '%v'.\n", commandName) return } // usages for _, usage := range command.Usages { if colour { usage = ansi.Bold(usage) } terminal.PrintWrapped(usage) } // description fmt.Println() description := colorize(command.Description) if !colour { description = ansi.Strip(description) } terminal.PrintWrapped(description) // examples if command.Examples != nil && len(command.Examples) > 0 { fmt.Println() text := "Examples:" if colour { text = ansi.Bold(text) } fmt.Println(text) fmt.Println() for _, example := range command.Examples { example = " " + strings.Replace(example, "\n", "\n ", -1) // preserve indent terminal.PrintWrapped(example) } } // aliases if command.Aliases != nil && len(command.Aliases) > 0 { fmt.Println() if command.Aliases != nil { text := "Aliases:" if colour { text = ansi.Bold(text) } fmt.Print(text) for _, alias := range command.Aliases { fmt.Print(" " + alias) } } fmt.Println() } // options if command.Options != nil && len(command.Options) > 0 { fmt.Println() text := "Options:" if colour { text = ansi.Bold(text) } fmt.Println(text) fmt.Println() printOptions(command.Options) } }