當前位置: 首頁>>代碼示例>>Golang>>正文


Golang goopt.Flag函數代碼示例

本文整理匯總了Golang中github.com/droundy/goopt.Flag函數的典型用法代碼示例。如果您正苦於以下問題:Golang Flag函數的具體用法?Golang Flag怎麽用?Golang Flag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Flag函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: cliSetup

func cliSetup() *cliOptions {

	options := newCliOptions()

	var httpVerb = goopt.StringWithLabel([]string{"-X", "--command"}, options.httpVerb,
		"COMMAND", fmt.Sprintf("HTTP verb for request: %s", HttpVerbs))
	var httpHeaders = goopt.Strings([]string{"-H", "--header"},
		"KEY:VALUE", "Custom HTTP Headers to be sent with request (can pass multiple times)")
	var postData = goopt.StringWithLabel([]string{"-d", "--data"}, options.postData,
		"DATA", "HTTP Data for POST")
	var timeOut = goopt.IntWithLabel([]string{"-t", "--timeout"}, options.timeout,
		"TIMEOUT", "Timeout in seconds for request")
	var shouldRedirect = goopt.Flag([]string{"-r", "--redirect"}, []string{}, "Follow redirects", "")
	var isVerbose = goopt.Flag([]string{"-v", "--verbose"}, []string{}, "Verbose output", "")
	var hasColor = goopt.Flag([]string{"-c", "--color"}, []string{}, "Colored output", "")
	var isInsecureSSL = goopt.Flag([]string{"-k", "--insecure"}, []string{}, "Allow insecure https connections", "")

	goopt.Summary = "Golang based http client program"
	goopt.Parse(nil)

	options.httpVerb = *httpVerb
	options.httpHeaders = *httpHeaders
	options.postData = *postData
	options.timeout = *timeOut
	options.verbose = *isVerbose
	options.redirect = *shouldRedirect
	options.color = *hasColor
	options.sslInsecure = *isInsecureSSL
	options.arguments = goopt.Args

	exitWithMessageIfNonZero(validateOptions(options))
	exitWithMessageIfNonZero(validateArguments(options))

	return options
}
開發者ID:jshort,項目名稱:gocurl,代碼行數:35,代碼來源:main.go

示例2: main

func main() {
	var no_cog = goopt.Flag([]string{"-C", "--no-cog"}, []string{"-c", "--cog"},
		"skip opening in cog", "open in cog")
	var no_delete = goopt.Flag([]string{"-D", "--no-delete"}, []string{"-d", "--delete"},
		"skip deleting original zip", "delete original zip")
	goopt.Parse(nil)

	boomkat(goopt.Args[0], *no_cog, *no_delete)

}
開發者ID:JonnieCache,項目名稱:boomkat,代碼行數:10,代碼來源:boomkat.go

示例3: main

func main() {
	goopt.Author = "William Pearson"
	goopt.Version = "Rmdir"
	goopt.Summary = "Remove each DIRECTORY if it is empty"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s [OPTION]... DIRECTORY...\n", os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless --help or --version is passed."
	}
	ignorefail := goopt.Flag([]string{"--ignore-fail-on-non-empty"}, nil,
		"Ignore each failure that is from a directory not being empty", "")
	parents := goopt.Flag([]string{"-p", "--parents"}, nil, "Remove DIRECTORY and ancestors if ancestors become empty", "")
	verbose := goopt.Flag([]string{"-v", "--verbose"}, nil, "Output each directory as it is processed", "")
	goopt.NoArg([]string{"--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	if len(goopt.Args) == 0 {
		coreutils.PrintUsage()
	}
	for i := range goopt.Args {
		filelisting, err := ioutil.ReadDir(goopt.Args[i])
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to remove %s: %v\n", os.Args[i+1], err)
			defer os.Exit(1)
			continue
		}
		if !*ignorefail && len(filelisting) > 0 {
			fmt.Fprintf(os.Stderr, "Failed to remove '%s' directory is non-empty\n", goopt.Args[i])
			defer os.Exit(1)
			continue
		}
		if *verbose {
			fmt.Printf("Removing directory %s\n", goopt.Args[i])
		}
		err = os.Remove(goopt.Args[i])
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to remove %s: %v\n", goopt.Args[i], err)
			defer os.Exit(1)
			continue
		}
		if !*parents {
			continue
		}
		dir := goopt.Args[i]
		if dir[len(dir)-1] == '/' {
			dir = filepath.Dir(dir)
		}
		if removeEmptyParents(dir, *verbose, *ignorefail) {
			defer os.Exit(1)
		}
	}
	return
}
開發者ID:uiri,項目名稱:coreutils,代碼行數:53,代碼來源:main.go

示例4: init

func init() {
	format = goopt.String([]string{"--fmt", "--format"}, "",
		"Log format (e.g. '$remote_addr [$time_local] \"$request\"')")
	nginxConfig = goopt.String([]string{"--nginx"}, "",
		"Nginx config to look for 'log_format' directive. You also should specify --nginx-format")
	nginxFormat = goopt.String([]string{"--nginx-format"}, "",
		"Name of nginx 'log_format', should be passed with --nginx option")
	aggField = goopt.String([]string{"-a", "--aggregate"}, "request_time",
		"Nginx access log variable to aggregate")
	groupBy = goopt.String([]string{"-g", "--group-by"}, "request",
		"Nginx access log variable to group by")
	groupByRegexp = goopt.String([]string{"-r", "--regexp"}, "",
		"You can specify regular expression to extract exact data from group by data. "+
			"For example, you might want to group by a path inside $request, so you should "+
			"set this option to '^\\S+\\s(.*)(?:\\?.*)?$'.")
	groupByGeneralize = goopt.String([]string{"--generalize"}, "",
		"Regular expression to generalize data. For example to make /foo/123 and /foo/234 equal")
	debug = goopt.Flag([]string{"--debug"}, []string{"--no-debug"},
		"Log debug information", "Do not log debug information")
	jsonOutput = goopt.String([]string{"-o", "--json"}, "",
		"Save result as json encoded file")
}
開發者ID:satyrius,項目名稱:log-parser,代碼行數:22,代碼來源:parser.go

示例5: main

func main() {
	var progname = os.Args[0][strings.LastIndex(os.Args[0], "/")+1:]

	var algorithm = goopt.StringWithLabel([]string{"-a", "--algorithm"}, algorithms[0],
		"ALG", fmt.Sprintf("Hashing algorithm: %s", algorithms))
	var version = goopt.Flag([]string{"-V", "--version"}, []string{}, "Display version", "")

	goopt.Summary = fmt.Sprintf("%s [OPTIONS] FILENAME\n\nMessage digest calculator with various hashing algorithms.\n\nArguments:\n  FILENAME                 File(s) to hash\n", progname)
	goopt.Parse(nil)

	var files []string = goopt.Args

	if *version {
		fmt.Printf("%s version %s\n", progname, Version)
		os.Exit(0)
	}

	validateAlgorithm(goopt.Usage(), *algorithm)
	valildateFiles(goopt.Usage(), files)

	calculateDigest(files, *algorithm)

	os.Exit(0)
}
開發者ID:jshort,項目名稱:go-hash,代碼行數:24,代碼來源:main.go

示例6: init

func init() {
	goopt.Description = func() string {
		return "conchk v" + goopt.Version
	}
	goopt.Author = "Bruce Fitzsimons <[email protected]>"
	goopt.Version = "0.3"
	goopt.Summary = "conchk is an IP connectivity test tool designed to validate that all configured IP connectivity actually works\n " +
		"It reads a list of tests and executes them, in a parallel manner, based on the contents of each line" +
		"conchk supports tcp and udp based tests (IPv4 and IPv6), at this time.\n\n" +
		"==Notes==\n" +
		"* The incuded Excel sheet is a useful way to create and maintain the tests\n" +
		"* testing a range of supports is supported. In this case the rules for a successful test are somewhat different\n" +
		"** If one of the ports gets a successful connect, and the rest are refused (connection refused) as nothing is listening\n" +
		"\tthen this is considered to be a successful test of the range. This is the most common scenario in our experience;\n" +
		"\tthe firewalls and routing are demonstrably working, and at least one destination service is ok. If you need all ports to work\n" +
		"\tthen consider using individual tests\n" +
		"* If all tests for this host pass, then conchk will exit(0). Otherwise it will exit(1)\n" +
		"* conchk will use the current hostname, or the commandline parameter, to find the tests approprate to execute - matches on field 3.\n" +
		"\tThis means all the tests for a system, or project can be placed in one file\n" +
		"* The .csv output option will write a file much like the input file, but with two additional columns and without any comments\n" +
		"\t This file can be fed back into conchk without error.\n\n" +
		"See http://bwooce.github.io/conchk/ for more information.\n\n(c)2013 Bruce Fitzsimons.\n\n"

	Hostname, _ := os.Hostname()

	params.Debug = goopt.Flag([]string{"-d", "--debug"}, []string{}, "additional debugging output", "")
	params.TestsFile = goopt.String([]string{"-T", "--tests"}, "./tests.conchk", "test file to load")
	params.OutputFile = goopt.String([]string{"-O", "--outputcsv"}, "", "name of results .csv file to write to. A pre-existing file will be overwritten.")
	params.MyHost = goopt.String([]string{"-H", "--host"}, Hostname, "Hostname to use for config lookup")
	params.MaxStreams = goopt.Int([]string{"--maxstreams"}, 8, "Maximum simultaneous checks")
	params.Timeout = goopt.String([]string{"--timeout"}, "5s", "TCP connectivity timeout, UDP delay for ICMP responses")

	semStreams = make(semaphore, *params.MaxStreams)
	runtime.GOMAXPROCS(runtime.NumCPU())

}
開發者ID:Bwooce,項目名稱:conchk,代碼行數:36,代碼來源:conchk.go

示例7:

	"encoding/json"
	"fmt"
	goopt "github.com/droundy/goopt"
	"net/http"
	"path/filepath"
	"strings"
)

var Version = "0.1"

var Summary = `gostatic path/to/config

Build a site.
`

var showVersion = goopt.Flag([]string{"-V", "--version"}, []string{},
	"show version and exit", "")
var showProcessors = goopt.Flag([]string{"--processors"}, []string{},
	"show internal processors", "")
var showSummary = goopt.Flag([]string{"--summary"}, []string{},
	"print everything on stdout", "")
var showConfig = goopt.Flag([]string{"--show-config"}, []string{},
	"dump config as JSON on stdout", "")
var doWatch = goopt.Flag([]string{"-w", "--watch"}, []string{},
	"watch for changes and serve them as http", "")
var port = goopt.String([]string{"-p", "--port"}, "8000",
	"port to serve on")
var verbose = goopt.Flag([]string{"-v", "--verbose"}, []string{},
	"enable verbose output", "")

// used in Page.Changed()
var force = goopt.Flag([]string{"-f", "--force"}, []string{},
開發者ID:minhajuddin,項目名稱:gostatic,代碼行數:32,代碼來源:gostatic.go

示例8: main

	"metrics.txt",
	"the name of the file that contains the list of metric names")
var maxMetrics = goopt.Int([]string{"-x", "--maxmetrics"},
	5000,
	"the maximum number of metric names that will be used. if the number exceeds the number of names in the metric file the max in the file will be used")
var target = goopt.Alternatives(
	[]string{"-t", "--target"},
	[]string{TARGET_MONGO, TARGET_ZMQ, TARGET_TSDB},
	"sets the destination of metrics generated, default is mongo")
var sendMode = goopt.Alternatives(
	[]string{"-m", "--sendmode"},
	[]string{MODE_CONNECT, MODE_BIND},
	"mode used when sending requests over ZeroMQ, default is connect")
var doBatching = goopt.Flag(
	[]string{"--batch"},
	[]string{"--nobatch"},
	"inserts into the database will be batched",
	"inserts into the database will not be batched")
var batchSize = goopt.Int(
	[]string{"-z", "--size", "--batchsize"},
	1000,
	"sets the size of batches when inserting into the database")

// Connects to a mongo database and sends a continuous stream of metric updates
// (inserts) to the server for a specified amount of time (default 60 seconds).
// At the end of the cycle the number of metrics inserted is displayed.
func main() {
	goopt.Description = func() string {
		return "Go test writer program for MongoDB."
	}
	goopt.Version = "1.0"
開發者ID:davidkbainbridge,項目名稱:writer,代碼行數:31,代碼來源:writer.go

示例9: Select

package promptcommit

import (
	"github.com/droundy/goopt"
	"../git/git"
	"../git/plumbing"
	"../util/out"
	"../util/error"
	"../util/exit"
	"../util/debug"
	box "./gotgo/box(git.CommitHash,git.Commitish)"
)

// To make --all the default, set *prompt.All to true.
var All = goopt.Flag([]string{"-a","--all"}, []string{"--interactive"},
	"verb all commits", "prompt for commits interactively")

var Dryrun = goopt.Flag([]string{"--dry-run"}, []string{},
	"just show commits that would be verbed", "xxxs")

var Verbose = goopt.Flag([]string{"-v","--verbose"}, []string{"-q","--quiet"},
	"output commits that are verbed", "don't output commits that are verbed")

func Select(since, upto git.Commitish) (outh git.CommitHash) {
	hs,e := plumbing.RevListDifference([]git.Commitish{upto}, []git.Commitish{since})
	error.FailOn(e)
	if len(hs) == 0 {
		out.Println(goopt.Expand("No commits to verb!"))
		exit.Exit(0)
	}
	if *Dryrun {
開發者ID:droundy,項目名稱:iolaus,代碼行數:31,代碼來源:promptcommit.go

示例10: setup_logger

	if err != 0 {
		return 0, err1
	}

	// Handle exception for darwin
	if darwin && r2 == 1 {
		r1 = 0
	}

	return r1, 0

}

var config_file = goopt.String([]string{"-c", "--config"}, "/etc/ranger.conf", "config file")
var install_api_key = goopt.String([]string{"-i", "--install-api-key"}, "", "install api key")
var amForeground = goopt.Flag([]string{"--foreground"}, []string{"--background"}, "run foreground", "run background")

func setup_logger() {
	filename := "/var/log/ranger/ranger.log"

	// Create a default logger that is logging messages of FINE or higher to filename, no rotation
	//    log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false))

	// =OR= Can also specify manually via the following: (these are the defaults, this is equivalent to above)
	flw := l4g.NewFileLogWriter(filename, false)
	if flw == nil {
		fmt.Printf("No permission to write to %s, going to switch to stdout only\n", filename)
	} else {
		flw.SetFormat("[%D %T] [%L] (%S) %M")
		flw.SetRotate(false)
		flw.SetRotateSize(0)
開發者ID:pombredanne,項目名稱:ranger-1,代碼行數:31,代碼來源:local_agent.go

示例11: log

import goopt "github.com/droundy/goopt"

import config "github.com/kless/goconfig/config"

var version = "0.1"

///////////////////////////////////
//
//		Taken form goopt example
//
///////////////////////////////////

// The Flag function creates a boolean flag, possibly with a negating
// alternative.  Note that you can specify either long or short flags
// naturally in the same list.
var amVerbose = goopt.Flag([]string{"-v", "--verbose"}, []string{"--quiet"},
	"output verbosely this will also show the graphite data", "be quiet, instead")

// This is just a logging function that uses the verbosity flags to
// decide whether or not to log anything.
func log(x ...interface{}) {
	if *amVerbose {
		fmt.Println(x...)
	}
}

///////////////////////////////////
///////////////////////////////////

func exists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
開發者ID:koumdros,項目名稱:vnx2graphite,代碼行數:32,代碼來源:vnx2graphite.go

示例12: main

import (
	"bytes"
	"log"
	"net"
	"os/exec"
	"regexp"
	"strings"
	"time"

	"github.com/droundy/goopt"
)

var connect = goopt.String([]string{"-s", "--server"}, "127.0.0.1", "Server to connect to (and listen if listening)")
var port = goopt.Int([]string{"-p", "--port"}, 2222, "Port to connect to (and listen to if listening)")

var listen = goopt.Flag([]string{"-l", "--listen"}, []string{}, "Create a listening TFO socket", "")

func main() {

	goopt.Parse(nil)

	// IPv4 only for no real reason, could be v6 by adjusting the sizes
	// here and where it's used
	var serverAddr [4]byte

	IP := net.ParseIP(*connect)
	if IP == nil {
		log.Fatal("Unable to process IP: ", *connect)
	}

	copy(serverAddr[:], IP[12:16])
開發者ID:zgbkny,項目名稱:tcp-fast-open,代碼行數:31,代碼來源:main.go

示例13: Run

package prompt

import (
	"github.com/droundy/goopt"
	"strings"
	"./core"
	"../git/color"
	"../util/out"
	"../util/error"
	"../util/debug"
	"../util/patience"
	ss "../util/slice(string)"
)

// To make --all the default, set *prompt.All to true.
var All = goopt.Flag([]string{"-a","--all"}, []string{"--interactive"},
	"verb all patches", "prompt for patches interactively")

func Run(ds []core.FileDiff, f func(core.FileDiff)) {
	if *All {
		for _,d := range ds {
			f(d)
		}
	} else {
	  files: for _,d := range ds {
			for {
				if !d.HasChange() {
					continue files
				}
				// Just keep asking until we get a reasonable answer...
				c,e := out.PromptForChar(goopt.Expand("Verb changes to %s? "), d.Name)
				error.FailOn(e)
開發者ID:droundy,項目名稱:iolaus,代碼行數:32,代碼來源:prompt.go

示例14: optToRegion

import "fmt"
import "os"

import (
	goopt "github.com/droundy/goopt"
	"github.com/rhettg/ftl/ftl"
	"launchpad.net/goamz/aws"
	"path/filepath"
	"strings"
)

const DOWNLOAD_WORKERS = 4

const Version = "0.2.6"

var amVerbose = goopt.Flag([]string{"-v", "--verbose"}, []string{"--quiet"},
	"output verbosely", "be quiet, instead")

var amMaster = goopt.Flag([]string{"--master"}, nil, "Execute against master repository", "")

var amVersion = goopt.Flag([]string{"--version"}, nil, "Display current version", "")

func optToRegion(regionName string) (region aws.Region) {
	region = aws.USEast

	switch regionName {
	case "us-east":
		region = aws.USEast
	case "us-west-1":
		region = aws.USWest
	case "us-west-2":
		region = aws.USWest2
開發者ID:rhettg,項目名稱:ftl,代碼行數:32,代碼來源:main.go

示例15: main

package main

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	"github.com/xaviershay/erg"
	"os"
	"strconv"
)

var port = goopt.Int([]string{"-p", "--port"}, 8080, "Port to connect to. Can also be set with RANGE_PORT environment variable.")
var host = goopt.String([]string{"-h", "--host"}, "localhost", "Host to connect to. Can also be set with RANGE_HOST environment variable.")
var ssl = goopt.Flag([]string{"-s", "--ssl"}, []string{"--no-ssl"},
	"Don't use SSL", "Use SSL. Can also be set with RANGE_SSL environment variable.")
var expand = goopt.Flag([]string{"-e", "--expand"}, []string{"--no-expand"},
	"Do not compress results", "Compress results (default)")

func main() {
	if envHost := os.Getenv("RANGE_HOST"); len(envHost) > 0 {
		*host = envHost
	}

	if envSsl := os.Getenv("RANGE_SSL"); len(envSsl) > 0 {
		*ssl = true
	}

	if envPort := os.Getenv("RANGE_PORT"); len(envPort) > 0 {
		x, err := strconv.Atoi(envPort)
		if err == nil {
			*port = x
		} else {
開發者ID:xaviershay,項目名稱:erg,代碼行數:31,代碼來源:erg.go


注:本文中的github.com/droundy/goopt.Flag函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。