Ejemplo n.º 1
0
func helpExec(options Options, args []string, databasePath string) (error, warnings) {
	var colour bool
	if options.HasOption("--color") {
		when := options.Get("--color").Argument
		switch when {
		case "auto":
			colour = terminal.Colour() && terminal.Width() > 0
		case "":
		case "always":
			colour = true
		case "never":
			colour = false
		default:
			return fmt.Errorf("invalid argument '%v' for '--color'", when), nil
		}
	} else {
		colour = terminal.Colour() && terminal.Width() > 0
	}

	if options.HasOption("--list") {
		listCommands()
	} else {
		switch len(args) {
		case 0:
			summary(colour)
		default:
			commandName := args[0]
			describeCommand(commandName, colour)
		}
	}

	return nil, nil
}
Ejemplo n.º 2
0
func useColour(options Options) (bool, error) {
	when := "auto"
	if options.HasOption("--color") {
		when = options.Get("--color").Argument
	}

	switch when {
	case "":
	case "auto":
		return terminal.Colour() && terminal.Width() > 0, nil
	case "always":
		return true, nil
	case "never":
		return false, nil
	}

	return false, fmt.Errorf("invalid argument '%v' for '--color'", when)
}