本文整理汇总了Golang中tmsu/cli.Options.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Options.Get方法的具体用法?Golang Options.Get怎么用?Golang Options.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmsu/cli.Options
的用法示例。
在下文中一共展示了Options.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Exec
func (command TagCommand) Exec(options cli.Options, args []string) error {
if len(args) < 1 {
return fmt.Errorf("too few arguments.")
}
command.verbose = options.HasOption("--verbose")
command.recursive = options.HasOption("--recursive")
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
switch {
case options.HasOption("--tags"):
tagNames := strings.Fields(options.Get("--tags").Argument)
if len(tagNames) == 0 {
return fmt.Errorf("set of tags to apply must be specified")
}
paths := args
if len(paths) < 1 {
return fmt.Errorf("at least one file to tag must be specified")
}
tagIds, err := command.lookupTagIds(store, tagNames)
if err != nil {
return err
}
if err := command.tagPaths(store, paths, tagIds); err != nil {
return err
}
case options.HasOption("--from"):
fromPath, err := filepath.Abs(options.Get("--from").Argument)
if err != nil {
return fmt.Errorf("%v: could not get absolute path: %v", fromPath, err)
}
tags, err := store.TagsForPath(fromPath)
if err != nil {
return fmt.Errorf("%v: could not retrieve tags: %v", fromPath)
}
tagIds := make([]uint, len(tags))
for index, tag := range tags {
tagIds[index] = tag.Id
}
for _, path := range args {
if err = command.tagPath(store, path, tagIds); err != nil {
return err
}
}
default:
if len(args) < 2 {
return fmt.Errorf("file to tag and tags to apply must be specified.")
}
path := args[0]
tagNames := args[1:]
tagIds, err := command.lookupTagIds(store, tagNames)
if err != nil {
return err
}
if err = command.tagPath(store, path, tagIds); err != nil {
return err
}
}
return nil
}
示例2: Exec
func (command UntagCommand) Exec(options cli.Options, args []string) error {
if len(args) < 1 {
return fmt.Errorf("no arguments specified.")
}
command.verbose = options.HasOption("--verbose")
command.recursive = options.HasOption("--recursive")
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
if options.HasOption("--all") {
if len(args) < 1 {
return fmt.Errorf("files to untag must be specified.")
}
paths := args
if err := command.untagPathsAll(store, paths); err != nil {
return err
}
} else if options.HasOption("--tags") {
tagNames := strings.Fields(options.Get("--tags").Argument)
if len(tagNames) == 0 {
return fmt.Errorf("set of tags to apply must be specified")
}
paths := args
if len(paths) < 1 {
return fmt.Errorf("at least one file to untag must be specified")
}
tagIds, err := command.lookupTagIds(store, tagNames)
if err != nil {
return err
}
if err := command.untagPaths(store, paths, tagIds); err != nil {
return err
}
} else {
if len(args) < 2 {
return fmt.Errorf("tag to remove and files to untag must be specified.")
}
path := args[0]
tagNames := args[1:]
tagIds, err := command.lookupTagIds(store, tagNames)
if err != nil {
return err
}
if err := command.untagPath(store, path, tagIds); err != nil {
return err
}
}
return nil
}