コード例 #1
0
ファイル: imply.go プロジェクト: kelvinhammond/tmsu
func (command ImplyCommand) listImplications(store *storage.Storage) error {
	if command.verbose {
		log.Infof("retrieving tag implications.")
	}

	implications, err := store.Implications()
	if err != nil {
		return fmt.Errorf("could not retrieve implications: %v", err)
	}

	width := 0
	for _, implication := range implications {
		length := len(implication.ImplyingTag.Name)
		if length > width {
			width = length
		}
	}

	previousImplyingTagName := ""
	for _, implication := range implications {
		if implication.ImplyingTag.Name != previousImplyingTagName {
			if previousImplyingTagName != "" {
				fmt.Println()
			}

			previousImplyingTagName = implication.ImplyingTag.Name

			fmt.Printf("%*v -> %v", width, implication.ImplyingTag.Name, implication.ImpliedTag.Name)
		} else {
			fmt.Printf(", %v", implication.ImpliedTag.Name)
		}
	}
	fmt.Println()

	return nil
}