Example #1
0
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")
}
Example #2
0
func versionExec(options Options, args []string, databasePath string) (error, warnings) {
	fmt.Println("TMSU", version.Version)
	fmt.Println()
	terminal.PrintWrapped(`Copyright © 2011-2016 Paul Ruane.

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the accompanying COPYING file for further details.`)

	return nil, nil
}
Example #3
0
func printOptions(options []Option) {
	maxWidth := 0
	for _, option := range options {
		maxWidth = int(math.Max(float64(maxWidth), float64(len(option.LongName))))
	}

	for _, option := range options {
		line := fmt.Sprintf("  %-2v %-*v   %v", option.ShortName, maxWidth, option.LongName, option.Description)
		terminal.PrintWrapped(line)
	}
}
Example #4
0
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)
	}
}