Example #1
0
File: info.go Project: logtcn/TMSU
func showUsage(store *storage.Storage, tx *storage.Tx, colour bool) error {
	tagUsages, err := store.TagUsage(tx)
	if err != nil {
		return fmt.Errorf("could not retrieve tag usage: %v", err)
	}

	maxLength := 0
	maxCountWidth := 0

	for _, tagUsage := range tagUsages {
		countWidth := int(math.Log(float64(tagUsage.FileCount)))
		if countWidth > maxCountWidth {
			maxCountWidth = countWidth
		}
		if len(tagUsage.Name) > maxLength {
			maxLength = len(tagUsage.Name)
		}
	}

	fmt.Println()
	for _, tagUsage := range tagUsages {
		fileCount := strconv.FormatUint(uint64(tagUsage.FileCount), 10)
		if colour {
			fileCount = ansi.Yellow(fileCount)
		}

		fmt.Printf("  %*s %*v\n", -maxLength, tagUsage.Name, maxCountWidth, fileCount)
	}

	return nil
}
Example #2
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")
}