当前位置: 首页>>代码示例>>Golang>>正文


Golang Options.HasOption方法代码示例

本文整理汇总了Golang中tmsu/cli.Options.HasOption方法的典型用法代码示例。如果您正苦于以下问题:Golang Options.HasOption方法的具体用法?Golang Options.HasOption怎么用?Golang Options.HasOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tmsu/cli.Options的用法示例。


在下文中一共展示了Options.HasOption方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Exec

func (command DupesCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")

	switch len(args) {
	case 0:
		command.findDuplicatesInDb()
	default:
		return command.findDuplicatesOf(args)
	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:12,代码来源:dupes.go

示例2: Exec

func (command UnmountCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")

	if options.HasOption("--all") {
		return command.unmountAll()
	}

	if len(args) < 1 {
		return fmt.Errorf("path to unmount not speciified.")
	}

	return command.unmount(args[0])
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:13,代码来源:unmount.go

示例3: Exec

func (command RenameCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")

	store, err := storage.Open()
	if err != nil {
		return fmt.Errorf("could not open storage: %v", err)
	}
	defer store.Close()

	if len(args) < 2 {
		return fmt.Errorf("tag to rename and new name must both be specified.")
	}

	if len(args) > 2 {
		return fmt.Errorf("too many arguments")
	}

	sourceTagName := args[0]
	destTagName := args[1]

	sourceTag, err := store.TagByName(sourceTagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", sourceTagName, err)
	}
	if sourceTag == nil {
		return fmt.Errorf("no such tag '%v'.", sourceTagName)
	}

	destTag, err := store.TagByName(destTagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", destTagName, err)
	}
	if destTag != nil {
		return fmt.Errorf("tag '%v' already exists.", destTagName)
	}

	if command.verbose {
		log.Infof("renaming tag '%v' to '%v'.", sourceTagName, destTagName)
	}

	_, err = store.RenameTag(sourceTag.Id, destTagName)
	if err != nil {
		return fmt.Errorf("could not rename tag '%v' to '%v': %v", sourceTagName, destTagName, err)
	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:47,代码来源:rename.go

示例4: Exec

func (command RepairCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")
	command.pretend = options.HasOption("--pretend")
	command.force = options.HasOption("--force")

	store, err := storage.Open()
	if err != nil {
		return fmt.Errorf("could not open storage: %v", err)
	}
	defer store.Close()

	if len(args) == 0 {
		return command.repairDatabase(store)
	}

	return command.repairPaths(store, args)
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:17,代码来源:repair.go

示例5: Exec

func (command StatusCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")
	command.directory = options.HasOption("--directory")

	var report *StatusReport
	var err error

	if len(args) == 0 {
		report, err = command.statusDatabase()
		if err != nil {
			return err
		}
	} else {
		report, err = command.statusPaths(args)
		if err != nil {
			return err
		}
	}

	for _, row := range report.Rows {
		if row.Status == TAGGED {
			command.printRow(row)
		}
	}

	for _, row := range report.Rows {
		if row.Status == MODIFIED {
			command.printRow(row)
		}
	}

	for _, row := range report.Rows {
		if row.Status == MISSING {
			command.printRow(row)
		}
	}

	for _, row := range report.Rows {
		if row.Status == UNTAGGED {
			command.printRow(row)
		}
	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:45,代码来源:status.go

示例6: Exec

func (VfsCommand) Exec(options cli.Options, args []string) error {
	if len(args) == 0 {
		fmt.Errorf("Mountpoint not specified.")
	}

	allowOther := options.HasOption("--allow-other")
	databasePath := args[0]
	mountPath := args[1]

	vfs, err := vfs.MountVfs(databasePath, mountPath, allowOther)
	if err != nil {
		return fmt.Errorf("could not mount virtual filesystem for database '%v' at '%v': %v", databasePath, mountPath, err)
	}
	defer vfs.Unmount()

	vfs.Loop()

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:19,代码来源:vfs.go

示例7: Exec

func (command ImplyCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")

	store, err := storage.Open()
	if err != nil {
		return fmt.Errorf("could not open storage: %v", err)
	}
	defer store.Close()

	switch {
	case options.HasOption("--list"):
		return command.listImplications(store)
	case options.HasOption("--delete"):
		if len(args) < 2 {
			return fmt.Errorf("Implying and implied tag must be specified.")
		}

		return command.deleteImplication(store, args[0], args[1])
	}

	if len(args) < 2 {
		return fmt.Errorf("Implying and implied tag must be specified.")
	}

	return command.addImplication(store, args[0], args[1])
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:26,代码来源:imply.go

示例8: Exec

func (command DeleteCommand) Exec(options cli.Options, args []string) error {
	if len(args) == 0 {
		return fmt.Errorf("no tags to delete specified.")
	}

	command.verbose = options.HasOption("--verbose")

	store, err := storage.Open()
	if err != nil {
		return fmt.Errorf("could not open storage: %v", err)
	}
	defer store.Close()

	for _, tagName := range args {
		err = command.deleteTag(store, tagName)
		if err != nil {
			return fmt.Errorf("could not delete tag '%v': %v", tagName, err)
		}
	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:22,代码来源:delete.go

示例9: Exec

func (command CopyCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")

	store, err := storage.Open()
	if err != nil {
		return fmt.Errorf("could not open storage: %v", err)
	}
	defer store.Close()

	sourceTagName := args[0]
	destTagName := args[1]

	sourceTag, err := store.Db.TagByName(sourceTagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", sourceTagName, err)
	}
	if sourceTag == nil {
		return fmt.Errorf("no such tag '%v'.", sourceTagName)
	}

	destTag, err := store.Db.TagByName(destTagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", destTagName, err)
	}
	if destTag != nil {
		return fmt.Errorf("a tag with name '%v' already exists.", destTagName)
	}

	if command.verbose {
		log.Infof("copying tag '%v' to '%v'.", sourceTagName, destTagName)
	}

	if _, err = store.CopyTag(sourceTag.Id, destTagName); err != nil {
		return fmt.Errorf("could not copy tag '%v' to '%v': %v", sourceTagName, destTagName, err)
	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:38,代码来源:copy.go

示例10: Exec

func (command TagsCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")
	command.count = options.HasOption("--count")

	if options.HasOption("--all") {
		return command.listAllTags()
	}

	return command.listTags(args)
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:10,代码来源:tags.go

示例11: Exec

func (command FilesCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")
	command.directory = options.HasOption("--directory")
	command.file = options.HasOption("--file")
	command.top = options.HasOption("--top")
	command.leaf = options.HasOption("--leaf")
	command.recursive = options.HasOption("--recursive")
	command.print0 = options.HasOption("--print0")
	command.count = options.HasOption("--count")

	if options.HasOption("--all") {
		return command.listAllFiles()
	}

	return command.listFilesForTags(args)
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:16,代码来源:files.go

示例12: 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
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:75,代码来源:tag.go

示例13: Exec

func (command MergeCommand) Exec(options cli.Options, args []string) error {
	command.verbose = options.HasOption("--verbose")

	if len(args) < 2 {
		return fmt.Errorf("too few arguments.")
	}

	store, err := storage.Open()
	if err != nil {
		return fmt.Errorf("could not open storage: %v", err)
	}
	defer store.Close()

	destTagName := args[len(args)-1]
	destTag, err := store.TagByName(destTagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", destTagName, err)
	}
	if destTag == nil {
		return fmt.Errorf("no such tag '%v'.", destTagName)
	}

	for _, sourceTagName := range args[0 : len(args)-1] {
		if sourceTagName == destTagName {
			return fmt.Errorf("source and destination names are the same.")
		}

		sourceTag, err := store.TagByName(sourceTagName)
		if err != nil {
			return fmt.Errorf("could not retrieve tag '%v': %v", sourceTagName, err)
		}
		if sourceTag == nil {
			return fmt.Errorf("no such tag '%v'.", sourceTagName)
		}

		if command.verbose {
			log.Infof("finding files tagged '%v'.", sourceTagName)
		}

		fileTags, err := store.FileTagsByTagId(sourceTag.Id)
		if err != nil {
			return fmt.Errorf("could not retrieve files for tag '%v': %v", sourceTagName, err)
		}

		if command.verbose {
			log.Infof("applying tag '%v' to these files.", destTagName)
		}

		for _, fileTag := range fileTags {
			_, err = store.AddFileTag(fileTag.FileId, destTag.Id)
			if err != nil {
				return fmt.Errorf("could not apply tag '%v' to file #%v: %v", destTagName, fileTag.FileId, err)
			}
		}

		if command.verbose {
			log.Infof("untagging files '%v'.", sourceTagName)
		}

		if err := store.RemoveFileTagsByTagId(sourceTag.Id); err != nil {
			return fmt.Errorf("could not remove all applications of tag '%v': %v", sourceTagName, err)
		}

		if command.verbose {
			log.Infof("updating tag implications involving tag '%v'.", sourceTagName)
		}

		if err := store.UpdateImplicationsForTagId(sourceTag.Id, destTag.Id); err != nil {
			return fmt.Errorf("could not update tag implications involving tag '%v': %v", sourceTagName, err)
		}

		if command.verbose {
			log.Infof("deleting tag '%v'.", sourceTagName)
		}

		err = store.DeleteTag(sourceTag.Id)
		if err != nil {
			return fmt.Errorf("could not delete tag '%v': %v", sourceTagName, err)
		}
	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:83,代码来源:merge.go

示例14: 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
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:63,代码来源:untag.go


注:本文中的tmsu/cli.Options.HasOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。