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

Golang goopt.Help函数代码示例

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

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



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

示例1: main

func main() {
	goopt.Suite = "XQZ coreutils"
	goopt.Author = "Aaron Muir Hamilton"
	goopt.Version = "Sleep v0.1"
	goopt.Summary = "Waits for a duration before continuing."
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage of %s:\n\t   %s STRING\n\tor %s OPTION\n", os.Args[0], os.Args[0], os.Args[0]) +
			goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
	goopt.Parse(nil)
	duration, err := time.ParseDuration(os.Args[1])
	if err != nil {
		number, interr := strconv.ParseFloat(os.Args[1], 64)
		if interr != nil {
			fmt.Println(err)
			os.Exit(0)
		}
		duration := time.Duration(number) * time.Second
		time.Sleep(duration)
		os.Exit(0)
	}
	time.Sleep(duration)
}
开发者ID:rafkhan,项目名称:coreutils,代码行数:27,代码来源:sleep.go


示例2: usage

func usage() string {
	u := `Usage: %s [-h HOST] [-p PORT]
       %s [-v VENDOR -s STATUS -c COLOR] <FILENAME>

%s`
	return fmt.Sprintf(u, os.Args[0], os.Args[0], goopt.Help())
}
开发者ID:jorik041,项目名称:buckler,代码行数:7,代码来源:main.go


示例3: main

func main() {
	atime = time.Now()
	mtime = time.Now()
	goopt.Author = "William Pearson"
	goopt.Version = "Touch"
	goopt.Summary = "Change access or modification time of each FILE"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s [OPTION]... FILE...\n", os.Args[0]) +
			goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless --help or --version is passed."
	}
	access := goopt.Flag([]string{"-a"}, nil, "Only change access time", "")
	modify := goopt.Flag([]string{"-m"}, nil, "Only change modification time", "")
	create := goopt.Flag([]string{"-c"}, nil, "Only change modification time", "")
	Nodereference = goopt.Flag([]string{"-h", "--no-dereference"}, []string{"--derference"}, "Affect symbolic links directly instead of dereferencing them", "Dereference symbolic links before operating on them (This is default)")
	goopt.OptArg([]string{"-r", "--reference"}, "RFILE", "Use RFILE's owner and group", fromReference)
	goopt.OptArg([]string{"-t"}, "STAMP", "Use [[CC]YY]MMDDhhmm[.ss] instead of now. Note hh is interpreted as from 00 to 23", fromStamp)
	goopt.NoArg([]string{"--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	coreutils.Noderef = *Nodereference
	if len(goopt.Args) == 0 {
		coreutils.PrintUsage()
	}
	if !*access && !*modify {
		*access, *modify = true, true
	}
	for i := range goopt.Args {
		if !*access {
			atime, _ = GetAtimeMtime(goopt.Args[i], *Nodereference)
		}
		if !*modify {
			_, mtime = GetAtimeMtime(goopt.Args[i], *Nodereference)
		}
		if err := os.Chtimes(goopt.Args[i], atime, mtime); err != nil {
			if os.IsNotExist(err) {
				var err error
				if !*create {
					f, err := os.Create(goopt.Args[i])
					if err == nil {
						f.Close()
					}
				}
				if err == nil {
					continue
				}
			}
			fmt.Fprintf(os.Stderr, "Error touching file '%s': %v\n", goopt.Args[i], err)
		}
	}
	return
}
开发者ID:uiri,项目名称:coreutils,代码行数:53,代码来源:main.go


示例4: main

func main() {
	goopt.Author = Author
	goopt.Version = Version
	goopt.Summary = Summary
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage of goreplace %s:\n\t", Version) +
			goopt.Summary + "\n" + goopt.Help()
	}

	var noIgnores bool
	for _, item := range os.Args[1:] {
		if item == "-I" || item == "--no-autoignore" {
			noIgnores = true
		}
	}

	cwd, _ := os.Getwd()
	ignorer := NewIgnorer(cwd, noIgnores)
	goopt.Summary += fmt.Sprintf("\n%s", ignorer)

	goopt.Parse(nil)


	if *showVersion {
		fmt.Printf("goreplace %s\n", goopt.Version)
		return
	}

	ignorer.Append(*ignoreFiles)

	if len(goopt.Args) == 0 {
		println(goopt.Usage())
		return
	}

	arg := goopt.Args[0]
	if *plaintext {
		arg = escapeRegex(arg)
	}
	if *ignoreCase {
		arg = "(?i:" + arg + ")"
	}

	pattern, err := regexp.Compile(arg)
	errhandle(err, true, "")

	if pattern.Match([]byte("")) {
		errhandle(errors.New("Your pattern matches empty string"), true, "")
	}

	searchFiles(pattern, ignorer)
}
开发者ID:vsolovyov,项目名称:goreplace,代码行数:52,代码来源:goreplace.go


示例5: main

func main() {
	goopt.Suite = "DevTodo2"
	goopt.Version = "2.1"
	goopt.Author = "Alec Thomas <[email protected]>"
	goopt.Description = func() string {
		return `DevTodo is a program aimed specifically at programmers (but usable by anybody
at the terminal) to aid in day-to-day development.

It maintains a list of items that have yet to be completed, one list for each
project directory. This allows the programmer to track outstanding bugs or
items that need to be completed with very little effort.

Items can be prioritised and are displayed in a hierarchy, so that one item may
depend on another.


todo2 [-A]
  Display (all) tasks.

todo2 [-p <priority>] -a <text>
  Create a new task.

todo2 -d <index>
  Mark a task as complete.

todo2 [-p <priority>] -e <task> [<text>]
  Edit an existing task.`
	}
	goopt.Summary = "DevTodo2 - a hierarchical command-line task manager"
	goopt.Usage = func() string {
		return fmt.Sprintf("usage: %s [<options>] ...\n\n%s\n\n%s",
			os.Args[0], goopt.Summary, goopt.Help())
	}
	goopt.Parse(nil)

	tasks, err := loadTaskList()
	if err != nil {
		fatal("%s", err)
	}
	if tasks == nil {
		tasks = NewTaskList()
	}
	processAction(tasks)
}
开发者ID:rdmo,项目名称:devtodo2,代码行数:44,代码来源:main.go


示例6: main

func main() {
	goopt.Version = version
	goopt.Summary = "send emc vnx performance data to graphite"
	goopt.Parse(nil)

	if f, _ := exists(*opt_conf); f == false {
		fmt.Print(goopt.Help())
		fmt.Println("ERROR: config file " + *opt_conf + " doesn't exist")
		return
	}
	c, _ := config.ReadDefault(*opt_conf)

	host, _ := c.String("graphite", "host")
	port, _ := c.Int("graphite", "port")
	timeout, _ := c.Int("graphite", "timeout")
	basename, _ := c.String("graphite", "basename")
	//todo: we also can parse this from the output...
	timestamp := time.Now().Unix()

	log(fmt.Sprintf("using graphite with host %s:%d", host, port))

	if f, _ := exists(*opt_data); f == false {
		fmt.Print(goopt.Help())
		fmt.Println("ERROR: data file " + *opt_data + " doesn't exist")
		return
	}
	lines, err := readLines(*opt_data)
	if err != nil {
		fmt.Println("ERROR:", err)
		return
	}
	//we only want to use the head and the first line of data
	head := strings.Split(lines[0], ",")
	data := strings.Split(lines[1], ",")

	if len(head) != len(data) {
		fmt.Println("ERROR: malformed csv (length of head != length of data")
		return
	}

	//create the graphite connection.
	// Todo: export this in a small pkg

	cstr := fmt.Sprintf("%s:%d", host, port)
	log("trying to connect to " + cstr)
	conn, err := net.DialTimeout("tcp", cstr, time.Duration(timeout)*time.Second)

	if err != nil {
		fmt.Println("ERROR:", err)
		return
	}

	for n, val := range head {
		key := stringify(val)
		value := stringify(data[n])
		if key != "Timestamp" {
			msg := fmt.Sprintf("%s.%s.%s.%s %s %d", basename, *opt_mover, *opt_statsname, key, value, timestamp)
			log("sending: " + msg)
			fmt.Fprint(conn, "\n"+msg+"\n")
		} else {
			log("Timestamp: ... next...")
		}
	}
	conn.Close()
}
开发者ID:koumdros,项目名称:vnx2graphite,代码行数:65,代码来源:vnx2graphite.go


示例7: optFail

func optFail(message string) {
	fmt.Println(message)
	fmt.Print(goopt.Help())
	os.Exit(1)
}
开发者ID:rhettg,项目名称:ftl,代码行数:5,代码来源:main.go


示例8: main

func main() {
	goopt.Suite = "XQZ coreutils"
	goopt.Author = "William Pearson"
	goopt.Version = "Unlink v0.1"
	goopt.Summary = "Uses unlink to remove FILE"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s FILE\n or:\t%s OPTION\n", os.Args[0], os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
	goopt.Parse(nil)
	switch {
	case len(os.Args) == 1:
		fmt.Println("Missing filenames")
	case len(os.Args) > 2:
		fmt.Println("Too many filenames")
	}
	if len(os.Args) != 2 {
		os.Exit(1)
	}
	file := os.Args[1]
	if err := syscall.Unlink(file); err != nil {
		fmt.Println("Encountered an error during unlinking: %v", err)
		os.Exit(1)
	}
	return
}
开发者ID:rafkhan,项目名称:coreutils,代码行数:29,代码来源:unlink.go


示例9: main

func main() {
	goopt.Suite = "XQZ coreutils"
	goopt.Author = "William Pearson"
	goopt.Version = "Link v0.1"
	goopt.Summary = "Creates a link to FILE1 called FILE2"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s FILE1 FILE2\n or:\t%s OPTION\n", os.Args[0], os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
	goopt.Parse(nil)
	switch {
	case len(os.Args) == 1:
		fmt.Println("Missing filenames")
	case len(os.Args) == 2:
		fmt.Println("Missing filename after '%s'", os.Args[1])
	case len(os.Args) > 3:
		fmt.Println("Too many filenames")
	}
	if len(os.Args) != 3 {
		os.Exit(1)
	}
	file1 := os.Args[1]
	file2 := os.Args[2]
	if err := os.Link(file1, file2); err != nil {
		fmt.Println("Encountered an error during linking: %v", err)
		os.Exit(1)
	}
	return
}
开发者ID:rafkhan,项目名称:coreutils,代码行数:32,代码来源:link.go


示例10: main

func main() {
	flag.Parse(nil)

	address_list := flag.Args
	if len(address_list) == 0 {
		fmt.Println("No Addresses submitted")
		fmt.Println(flag.Help())
		return
	}

	var send, recv bool
	skip := false

	var socket *zmq.Socket
	switch *socket_type {
	case "PUSH":
		socket, _ = zmq.NewSocket(zmq.PUSH)
		send = true
	case "PULL":
		socket, _ = zmq.NewSocket(zmq.PULL)
		recv = true
	case "PUB":
		socket, _ = zmq.NewSocket(zmq.PUB)
		send = true
	case "SUB":
		socket, _ = zmq.NewSocket(zmq.SUB)
		recv = true
		if len(*subscriptions) == 0 {
			socket.SetSubscribe("")
		}
		for _, subscription := range *subscriptions {
			socket.SetSubscribe(subscription)
		}
	case "REQ":
		socket, _ = zmq.NewSocket(zmq.REQ)
		send = true
		recv = true
	case "REP":
		socket, _ = zmq.NewSocket(zmq.REP)
		send = true
		recv = true
		skip = true
	}
	defer socket.Close()

	// connect or bind
	if *mode {
		for _, address := range address_list {
			socket.Connect(address)
		}
	} else {
		for _, address := range address_list {
			socket.Bind(address)
		}
	}

	delim := byte('\n')
	if *null {
		fmt.Println("Setting delim to null")
		delim = byte(0x00)
	}

	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	for i := 0; i < *number || *number == -1; i++ {
		if send && !skip {
			line, _ := reader.ReadBytes(delim)
			socket.SendBytes([]byte(line), 0)
		}
		if recv {
			data, _ := socket.RecvBytes(0)
			writer.Write(data)
			writer.Flush()
		}
		if skip {
			skip = false
		}
	}

	fmt.Println("finished", *number)
}
开发者ID:jhawk28,项目名称:zmqc,代码行数:82,代码来源:zmqc.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang goopt.NoArg函数代码示例发布时间:2022-05-23
下一篇:
Golang goopt.Flag函数代码示例发布时间: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