本文整理汇总了Golang中tmsu/storage.Storage.TagsForPath方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.TagsForPath方法的具体用法?Golang Storage.TagsForPath怎么用?Golang Storage.TagsForPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmsu/storage.Storage
的用法示例。
在下文中一共展示了Storage.TagsForPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: listTagsForPath
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
}
示例2: listTagsForPaths
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
}
示例3: listTagsForWorkingDirectory
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
}