Esempio n. 1
0
File: imply.go Progetto: logtcn/TMSU
func listImplications(store *storage.Storage, tx *storage.Tx, colour bool) error {
	log.Infof(2, "retrieving tag implications.")

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

	width := 0
	for _, implication := range implications {
		length := len(implication.ImplyingTag.Name)
		if implication.ImplyingValue.Id != 0 {
			length += 1 + len(implication.ImplyingValue.Name)
		}

		if length > width {
			width = length
		}
	}

	if len(implications) > 0 {
		for _, implication := range implications {
			implying := formatTagValueName(implication.ImplyingTag.Name, implication.ImplyingValue.Name, colour, false, true)
			implied := formatTagValueName(implication.ImpliedTag.Name, implication.ImpliedValue.Name, colour, true, false)

			fmt.Printf("%*v -> %v\n", width, implying, implied)
		}
	}

	return nil
}