• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang uggo.NewFlagSetDefault函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/laher/uggo.NewFlagSetDefault函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFlagSetDefault函数的具体用法?Golang NewFlagSetDefault怎么用?Golang NewFlagSetDefault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: Unzip

func Unzip(call []string) error {

	flagSet := uggo.NewFlagSetDefault("unzip", "[options] file.zip [list]", VERSION)
	destDir := "."
	flagSet.StringVar(&destDir, "d", destDir, "destination directory")
	test := false
	flagSet.BoolVar(&test, "t", test, "test archive data")

	err := flagSet.Parse(call[1:])
	if err != nil {
		return err
	}
	if flagSet.ProcessHelpOrVersion() {
		return nil
	}
	args := flagSet.Args()
	if len(args) < 1 {
		return errors.New("No zip filename given")
	}
	zipname := args[0]
	files := args[1:]
	if test {
		err = TestItems(zipname, files)
		if err != nil {
			return err
		}
	} else {
		err = UnzipItems(zipname, destDir, files)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:ngpestelos,项目名称:someutils,代码行数:34,代码来源:unzip.go


示例2: Rm

func Rm(call []string) error {
	options := RmOptions{}
	flagSet := uggo.NewFlagSetDefault("rm", "[options] [files...]", VERSION)
	flagSet.BoolVar(&options.IsRecursive, "r", false, "Recurse into directories")

	e := flagSet.Parse(call[1:])
	if e != nil {
		return e
	}
	if flagSet.ProcessHelpOrVersion() {
		return nil
	}
	for _, fileGlob := range flagSet.Args() {
		files, err := filepath.Glob(fileGlob)
		if err != nil {
			return err
		}
		for _, file := range files {
			e := delete(file, options.IsRecursive)
			if e != nil {
				return e
			}
		}
	}

	return nil
}
开发者ID:ngpestelos,项目名称:someutils,代码行数:27,代码来源:rm.go


示例3: Gunzip

func Gunzip(call []string) error {
	options := GunzipOptions{}
	flagSet := uggo.NewFlagSetDefault("gunzip", "[options] file.gz [list]", VERSION)
	flagSet.AliasedBoolVar(&options.IsTest, []string{"t", "test"}, false, "test archive data")
	flagSet.AliasedBoolVar(&options.IsKeep, []string{"k", "keep"}, false, "keep gzip file")

	err := flagSet.Parse(call[1:])
	if err != nil {
		return err
	}
	if flagSet.ProcessHelpOrVersion() {
		return nil
	}
	args := flagSet.Args()
	//TODO STDIN support
	if len(args) < 1 {
		return errors.New("No gzip filename given")
	}
	if options.IsTest {
		err = TestGzipItems(args)
		if err != nil {
			return err
		}
	} else {
		err = GunzipItems(args, options)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:jayvansantos,项目名称:someutils,代码行数:31,代码来源:gunzip.go


示例4: Which

func Which(call []string) error {
	options := WhichOptions{}
	flagSet := uggo.NewFlagSetDefault("which", "[-a] args", VERSION)
	flagSet.BoolVar(&options.all, "a", false, "Print all matching executables in PATH, not just the first.")

	err := flagSet.Parse(call[1:])
	if err != nil {
		println("Error parsing flags")
		return err
	}
	if flagSet.ProcessHelpOrVersion() {
		return nil
	}

	args := flagSet.Args()
	path := os.Getenv("PATH")
	if runtime.GOOS == "windows" {
		path = ".;" + path
	}
	pl := filepath.SplitList(path)
	for _, arg := range args {
		checkPathParts(arg, pl, options)
		/*
			if err != nil {
				return err
			}*/
	}
	return nil
}
开发者ID:ngpestelos,项目名称:someutils,代码行数:29,代码来源:which.go


示例5: ParseFlags

// ParseFlags parses commandline options.
func (tr *SomeTr) ParseFlags(call []string, errWriter io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("tr", "[OPTION]... SET1 [SET2]", someutils.VERSION)
	flagSet.SetOutput(errWriter)
	flagSet.AliasedBoolVar(&tr.IsDelete, []string{"d", "delete"}, false, "Delete characters in SET1, do not translate")
	flagSet.AliasedBoolVar(&tr.IsSqueeze, []string{"s", "squeeze-repeats"}, false, "replace each input sequence of a repeated character that is listed in SET1 with a single occurence of that character")
	//Don't get the Complement thing. Just don't understand it right now.
	flagSet.AliasedBoolVar(&tr.IsComplement, []string{"c", "complement"}, false, "use the complement of SET1")
	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	sets := flagSet.Args()
	if len(sets) > 0 {
		tr.set1 = sets[0]
	} else {
		return errors.New("Not enough args supplied"), 1
	}
	if len(sets) > 1 {
		tr.set2 = sets[1]
	} else if !tr.IsDelete {
		return errors.New("Not enough args supplied"), 1
	}
	err = tr.Preprocess()
	if err != nil {
		return err, 1
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:29,代码来源:tr.go


示例6: ParseFlags

// ParseFlags parses flags from a commandline []string
func (grep *SomeGrep) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("grep", "[options] PATTERN [files...]", someutils.VERSION)
	flagSet.SetOutput(errPipe)
	flagSet.AliasedBoolVar(&grep.IsPerl, []string{"P", "perl-regexp"}, false, "Perl-style regex")
	flagSet.AliasedBoolVar(&grep.IsExtended, []string{"E", "extended-regexp"}, true, "Extended regex (default)")
	flagSet.AliasedBoolVar(&grep.IsIgnoreCase, []string{"i", "ignore-case"}, false, "ignore case")
	flagSet.AliasedBoolVar(&grep.IsPrintFilename, []string{"H", "with-filename"}, true, "print the file name for each match")
	flagSet.AliasedBoolVar(&grep.IsPrintLineNumber, []string{"n", "line-number"}, false, "print the line number for each match")
	flagSet.AliasedBoolVar(&grep.IsInvertMatch, []string{"v", "invert-match"}, false, "invert match")
	// disable for now
	//	flagSet.AliasedBoolVar(&grep.IsRecurse, []string{"r", "recurse"}, false, "recurse into subdirectories")

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	args := flagSet.Args()
	if len(args) < 1 {
		flagSet.Usage()
		return errors.New("Not enough args"), 1
	}
	grep.pattern = args[0]

	if len(args) > 1 {
		grep.globs = args[1:]
	} else {
		grep.globs = []string{}
	}

	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:32,代码来源:grep.go


示例7: Ln

func Ln(call []string) error {
	options := LnOptions{}
	flagSet := uggo.NewFlagSetDefault("ln", "[options] TARGET LINK_NAME", VERSION)
	flagSet.BoolVar(&options.IsSymbolic, "s", false, "Symbolic")
	flagSet.BoolVar(&options.IsForce, "f", false, "Force")

	e := flagSet.Parse(call[1:])
	if e != nil {
		println("Error parsing flags")
		return e
	}
	if flagSet.ProcessHelpOrVersion() {
		return nil
	}

	args := flagSet.Args()
	if len(args) < 2 {
		flagSet.Usage()
		return errors.New("Not enough args!")
	}
	target := args[0]
	linkName := args[1]
	return makeLink(target, linkName, options)

}
开发者ID:ngpestelos,项目名称:someutils,代码行数:25,代码来源:ln.go


示例8: Grep

func Grep(call []string) error {

	options := GrepOptions{}
	flagSet := uggo.NewFlagSetDefault("grep", "[options] PATTERN [files...]", VERSION)
	flagSet.AliasedBoolVar(&options.IsPerl, []string{"P", "perl-regexp"}, false, "Perl-style regex")
	flagSet.AliasedBoolVar(&options.IsExtended, []string{"E", "extended-regexp"}, true, "Extended regex (default)")
	flagSet.AliasedBoolVar(&options.IsIgnoreCase, []string{"i", "ignore-case"}, false, "ignore case")
	flagSet.AliasedBoolVar(&options.IsPrintFilename, []string{"H", "with-filename"}, true, "print the file name for each match")
	flagSet.AliasedBoolVar(&options.IsPrintLineNumber, []string{"n", "line-number"}, false, "print the line number for each match")
	flagSet.AliasedBoolVar(&options.IsInvertMatch, []string{"v", "invert-match"}, false, "invert match")
	// disable for now
	//	flagSet.AliasedBoolVar(&options.IsRecurse, []string{"r", "recurse"}, false, "recurse into subdirectories")

	err := flagSet.Parse(call[1:])
	if err != nil {
		flagSet.Usage()
		return err
	}
	if flagSet.ProcessHelpOrVersion() {
		return nil
	}
	args := flagSet.Args()
	if len(args) < 1 {
		flagSet.Usage()
		return errors.New("Not enough args")
	}
	pattern := args[0]
	reg, err := compile(pattern, options)
	if err != nil {
		return err
	}

	globs := []string{}
	if len(args) > 1 {
		globs = args[1:]
		files := []string{}
		for _, glob := range globs {
			results, err := filepath.Glob(glob)
			if err != nil {
				return err
			}
			if len(results) < 1 { //no match
				return errors.New("grep: cannot access " + glob + ": No such file or directory")
			}
			files = append(files, results...)
		}
		return grep(reg, files, options)
	} else {
		if uggo.IsPipingStdin() {
			//check STDIN
			return grepReader(os.Stdin, "", reg, options)
		} else {
			//NOT piping.
			return errors.New("Not enough args")
		}
	}
}
开发者ID:jayvansantos,项目名称:someutils,代码行数:57,代码来源:grep.go


示例9: ParseFlags

// ParseFlags parses flags from a commandline []string
func (pwd *SomePwd) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("pwd", "", someutils.VERSION)
	flagSet.SetOutput(errPipe)

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:11,代码来源:pwd.go


示例10: ParseFlags

// ParseFlags parses flags from a commandline []string
func (dirname *SomeDirname) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("dirname", "[options] NAME...", someutils.VERSION)
	flagSet.SetOutput(errPipe)

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	dirname.Filenames = flagSet.Args()
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:12,代码来源:dirname.go


示例11: ParseFlags

// ParseFlags parses flags from a commandline []string
func (tee *SomeTee) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("tee", "[OPTION]... [FILE]...", someutils.VERSION)
	flagSet.SetOutput(errPipe)
	flagSet.AliasedBoolVar(&tee.isAppend, []string{"a", "append"}, false, "Append instead of overwrite")

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}

	tee.args = flagSet.Args()
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:14,代码来源:tee.go


示例12: ParseFlags

// ParseFlags parses flags from a commandline []string
func (which *SomeWhich) ParseFlags(call []string, errWriter io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("which", "[options] [args...]", someutils.VERSION)
	flagSet.SetOutput(errWriter)

	flagSet.BoolVar(&which.all, "a", false, "Print all matching executables in PATH, not just the first.")

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}

	which.args = flagSet.Args()
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:15,代码来源:which.go


示例13: ParseFlags

// ParseFlags parses flags from a commandline []string
func (rm *SomeRm) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("rm", "[options] [files...]", someutils.VERSION)
	flagSet.SetOutput(errPipe)

	flagSet.BoolVar(&rm.IsRecursive, "r", false, "Recurse into directories")

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}

	rm.fileGlobs = flagSet.Args()
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:15,代码来源:rm.go


示例14: ParseFlags

// ParseFlags parses flags from a commandline []string
func (head *SomeHead) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("head", "[options] [args...]", someutils.VERSION)
	flagSet.SetOutput(errPipe)

	flagSet.AliasedIntVar(&head.lines, []string{"n", "lines"}, 10, "number of lines to print")

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	//could be nil
	head.Filenames = flagSet.Args()
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:15,代码来源:head.go


示例15: ParseFlags

// ParseFlags parses flags from a commandline []string
func (touch *SomeTouch) ParseFlags(call []string, errWriter io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("touch", "[options] [files...]", someutils.VERSION)
	flagSet.SetOutput(errWriter)

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}

	args := flagSet.Args()
	if len(args) < 1 {
		return errors.New("Not enough args given"), 1
	}
	touch.args = args
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:17,代码来源:touch.go


示例16: ParseFlags

// ParseFlags parses flags from a commandline []string
func (tail *SomeTail) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("tail", "[options] [args...]", someutils.VERSION)
	flagSet.SetOutput(errPipe)

	flagSet.AliasedIntVar(&tail.Lines, []string{"n", "lines"}, 10, "number of lines to print")
	flagSet.AliasedFloat64Var(&tail.SleepInterval, []string{"s", "sleep"}, 1.0, "how long to sleep")
	//TODO!
	//flagSet.AliasedStringVar(&options.Follow, []string{"f", "follow"}, "", "follow (name|descriptor). Default is by descriptor (unsupported so far!!)")
	flagSet.BoolVar(&tail.FollowByName, "F", false, "follow by name")

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	tail.Filenames = flagSet.Args()
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:18,代码来源:tail.go


示例17: ParseFlags

// ParseFlags parses flags from a commandline []string
func (z *SomeZip) ParseFlags(call []string, errWriter io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("zip", "[options] [files...]", someutils.VERSION)
	flagSet.SetOutput(errWriter)

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	args := flagSet.Args()
	if len(args) < 2 {
		flagSet.Usage()
		return errors.New("Not enough args given"), 1
	}
	z.zipFilename = args[0]
	z.items = args[1:]
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:18,代码来源:zip.go


示例18: ParseFlags

// ParseFlags parses flags from a commandline []string
func (wc *SomeWc) ParseFlags(call []string, errWriter io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("wc", "[OPTION]... [FILE]...", someutils.VERSION)
	flagSet.SetOutput(errWriter)

	// TODO add flags here
	flagSet.AliasedBoolVar(&wc.IsLines, []string{"l", "lines"}, false, "Count lines")
	flagSet.AliasedBoolVar(&wc.IsWords, []string{"w", "words"}, false, "Count words")
	//	flagSet.AliasedBoolVar(&wc.IsChars, []string{"m", "chars"}, false, "Count characters")
	flagSet.AliasedBoolVar(&wc.IsBytes, []string{"c", "bytes"}, false, "Count bytes")

	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}

	wc.args = flagSet.Args()
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:19,代码来源:wc.go


示例19: Pwd

func Pwd(call []string) error {

	flagSet := uggo.NewFlagSetDefault("pwd", "", VERSION)

	err := flagSet.Parse(call[1:])
	if err != nil {
		return err
	}
	if flagSet.ProcessHelpOrVersion() {
		return nil
	}
	wd, err := os.Getwd()
	if err != nil {
		return err
	}
	println(wd)
	return nil
}
开发者ID:ngpestelos,项目名称:someutils,代码行数:18,代码来源:pwd.go


示例20: ParseFlags

// ParseFlags parses flags from a commandline []string
func (basename *SomeBasename) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("basename", "", someutils.VERSION)
	flagSet.SetOutput(errPipe)
	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}
	if len(flagSet.Args()) < 1 {
		return errors.New("Missing operand"), 1
	}
	if len(flagSet.Args()) > 1 {
		basename.RelativeTo = flagSet.Args()[0]
		basename.InputPath = flagSet.Args()[1]
	} else {
		basename.InputPath = flagSet.Args()[0]
	}
	return nil, 1
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:19,代码来源:basename.go



注:本文中的github.com/laher/uggo.NewFlagSetDefault函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goth.Params类代码示例发布时间:2022-05-23
下一篇:
Golang someutils.Invocation类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap