func (command TagsCommand) listTagsForPath(store *storage.Storage, path string) error { if command.verbose { log.Infof("%v: retrieving tags.", path) } var tags, err = store.TagsForPath(path) if err != nil { return fmt.Errorf("%v: could not retrieve tags: %v", path, err) } if len(tags) == 0 { _, err := os.Stat(path) if err != nil { switch { case os.IsPermission(err): log.Warnf("%v: permission denied", path) case os.IsNotExist(err): return fmt.Errorf("%v: file not found", path) default: return fmt.Errorf("%v: could not stat file: %v", path, err) } } } if command.count { log.Print(len(tags)) } else { for _, tag := range tags { log.Print(tag.Name) } } return nil }
func (command TagsCommand) listTagsForPaths(store *storage.Storage, paths []string) error { for _, path := range paths { if command.verbose { log.Infof("%v: retrieving tags.", path) } var tags, err = store.TagsForPath(path) if err != nil { log.Warn(err.Error()) continue } if command.count { log.Print(path + ": " + strconv.Itoa(len(tags))) } else { log.Print(path + ": " + tagLine(tags)) } } return nil }
func (command TagsCommand) listTagsForWorkingDirectory(store *storage.Storage) error { file, err := os.Open(".") if err != nil { return fmt.Errorf("could not open working directory: %v", err) } defer file.Close() dirNames, err := file.Readdirnames(0) if err != nil { return fmt.Errorf("could not list working directory contents: %v", err) } sort.Strings(dirNames) for _, dirName := range dirNames { if command.verbose { log.Infof("%v: retrieving tags.", dirName) } var tags, err = store.TagsForPath(dirName) if err != nil { log.Warn(err.Error()) continue } if len(tags) == 0 { continue } if command.count { log.Print(dirName + ": " + strconv.Itoa(len(tags))) } else { log.Print(dirName + ": " + tagLine(tags)) } } return nil }