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


Golang FlagSet.Init方法代碼示例

本文整理匯總了Golang中flag.FlagSet.Init方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagSet.Init方法的具體用法?Golang FlagSet.Init怎麽用?Golang FlagSet.Init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flag.FlagSet的用法示例。


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

示例1: ParamsParser

func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		fs       flag.FlagSet
		pkgMatch flagParam
		verMatch string
	)

	if len(args) < 1 || args[0] == "" || args[0] == "help" {
		printHelp(true)
		return nil, nil
	}

	fs.Init("pkg", flag.ContinueOnError)
	fs.Var(&pkgMatch, "name", "see help")
	fs.StringVar(&verMatch, "version", "", "see help")
	err := fs.Parse(args)
	if err != nil {
		return nil, err
	}

	p := newParameters()
	p.PkgMatch.Matches = pkgMatch
	if verMatch != "" {
		p.VerMatch = verMatch
	}

	r.Parameters = *p

	return r.Parameters, r.ValidateParameters()
}
開發者ID:ZhuHangpeng,項目名稱:mig,代碼行數:30,代碼來源:paramscreator.go

示例2: ParamsParser

// ParamsParser implements a command line parameter parser for the ping module
func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		err      error
		pa       params
		d, p     string
		dp, c, t float64
		fs       flag.FlagSet
	)
	if len(args) < 1 || args[0] == "" || args[0] == "help" {
		printHelp(true)
		return nil, fmt.Errorf("help printed")
	}
	fs.Init("ping", flag.ContinueOnError)
	fs.StringVar(&d, "d", "www.google.com", "see help")
	fs.Float64Var(&dp, "dp", -1, "see help")
	fs.StringVar(&p, "p", "icmp", "see help")
	fs.Float64Var(&c, "c", 3, "see help")
	fs.Float64Var(&t, "t", 5, "see help")

	err = fs.Parse(args)
	if err != nil {
		return nil, err
	}
	pa.Destination = d
	pa.DestinationPort = dp
	pa.Protocol = p
	pa.Count = c
	pa.Timeout = t
	r.Parameters = pa
	return pa, r.ValidateParameters()
}
開發者ID:rayyang2000,項目名稱:mig,代碼行數:32,代碼來源:paramscreator.go

示例3: ParamsParser

func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		err   error
		drift string
		fs    flag.FlagSet
	)
	if len(args) >= 1 && args[0] == "help" {
		printHelp(true)
		return nil, fmt.Errorf("help printed")
	}
	if len(args) == 0 {
		return r.Parameters, nil
	}
	fs.Init("time", flag.ContinueOnError)
	fs.StringVar(&drift, "drift", "", "see help")
	err = fs.Parse(args)
	if err != nil {
		return nil, err
	}
	_, err = time.ParseDuration(drift)
	if err != nil {
		return nil, fmt.Errorf("invalid drift duration. try help.")
	}
	r.Parameters.Drift = drift
	return r.Parameters, r.ValidateParameters()
}
開發者ID:tudalex,項目名稱:mig,代碼行數:26,代碼來源:timedrift.go

示例4: ParamsParser

func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		fs          flag.FlagSet
		scribeDoc   string
		onlyTrue    bool
		outputHuman bool
		outputJSON  bool
	)

	if len(args) < 1 || args[0] == "" || args[0] == "help" {
		printHelp(true)
		return nil, nil
	}

	fs.Init("scribe", flag.ContinueOnError)
	fs.StringVar(&scribeDoc, "path", "", "see help")
	fs.BoolVar(&outputHuman, "human", false, "see help")
	fs.BoolVar(&outputJSON, "json", false, "see help")
	fs.BoolVar(&onlyTrue, "onlytrue", false, "see help")
	err := fs.Parse(args)
	if err != nil {
		return nil, err
	}

	p := newParameters()

	p.HumanOutput = outputHuman
	p.JSONOutput = outputJSON

	if scribeDoc == "" {
		return nil, fmt.Errorf("-path option is required")
	}
	dp, err := loadScribeDocument(scribeDoc)
	if err != nil {
		return nil, err
	}
	p.ScribeDoc = *dp
	p.OnlyTrue = onlyTrue

	r.Parameters = *p

	return r.Parameters, r.ValidateParameters()
}
開發者ID:zaktwo,項目名稱:mig,代碼行數:43,代碼來源:paramscreator.go

示例5: ParamsParser

// ParamsParser implements a command line parameters parser that takes a string
// and returns a Parameters structure in an interface. It will display the module
// help if the arguments string spell the work 'help'
func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		err                               error
		names, libraries, bytes, contents flagParam
		offset, maxlength                 float64
		matchall, matchany, logfailures   bool
		fs                                flag.FlagSet
	)
	if len(args) < 1 || args[0] == "" || args[0] == "help" {
		printHelp(true)
		return nil, nil
	}
	fs.Init("memory", flag.ContinueOnError)
	fs.Var(&names, "name", "see help")
	fs.Var(&libraries, "lib", "see help")
	fs.Var(&bytes, "bytes", "see help")
	fs.Var(&contents, "content", "see help")
	fs.Float64Var(&offset, "maxdepth", 0, "see help")
	fs.Float64Var(&maxlength, "matchlimit", 0, "see help")
	fs.BoolVar(&matchall, "matchall", true, "see help")
	fs.BoolVar(&matchany, "matchany", false, "see help")
	fs.BoolVar(&logfailures, "logfailures", false, "see help")
	err = fs.Parse(args)
	if err != nil {
		return nil, err
	}
	var s search
	s.Names = names
	s.Libraries = libraries
	s.Bytes = bytes
	s.Contents = contents
	s.Options.Offset = offset
	s.Options.MaxLength = maxlength
	s.Options.MatchAll = matchall
	if matchany {
		s.Options.MatchAll = false
	}
	s.Options.LogFailures = logfailures
	p := newParameters()
	p.Searches["s1"] = s
	r.Parameters = *p
	return r.Parameters, r.ValidateParameters()
}
開發者ID:rayyang2000,項目名稱:mig,代碼行數:46,代碼來源:params.go

示例6: getOpts

// getOpts returns command line flags and values or displays help
func getOpts() *opts {
	var flags flag.FlagSet
	flags.Init("blacklist", flag.ExitOnError)
	flags.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %v [options]\n\n", basename(os.Args[0]))
		flags.PrintDefaults()
	}

	return &opts{
		ARCH:    flags.String("arch", runtime.GOARCH, "Set EdgeOS CPU architecture"),
		Dbug:    flags.Bool("debug", false, "Enable debug mode"),
		DNSdir:  flags.String("dir", "/etc/dnsmasq.d", "Override dnsmasq directory"),
		DNStmp:  flags.String("tmp", "/tmp", "Override dnsmasq temporary directory"),
		Help:    flags.Bool("h", false, "Display help"),
		File:    flags.String("f", "", "`<file>` # Load a configuration file"),
		FlagSet: &flags,
		MIPS64:  flags.String("mips64", "mips64", "Override target EdgeOS CPU architecture"),
		OS:      flags.String("os", runtime.GOOS, "Override native EdgeOS OS"),
		Poll:    flags.Int("i", 5, "Polling interval"),
		Test:    flags.Bool("t", false, "Run config and data validation tests"),
		Verb:    flags.Bool("v", false, "Verbose display"),
		Version: flags.Bool("version", false, "Show version"),
	}
}
開發者ID:britannic,項目名稱:blacklist,代碼行數:25,代碼來源:opts.go

示例7: ParamsParser

// ParamsParser implements a command line parameters parser that takes a string
// and returns a Parameters structure in an interface. It will display the module
// help if the arguments string spell the work 'help'
func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		err error
		paths, names, sizes, modes, mtimes, contents, md5s, sha1s, sha2s,
		sha3s, mismatch flagParam
		maxdepth, matchlimit                                           float64
		returnsha256, matchall, matchany, macroal, verbose, decompress bool
		fs                                                             flag.FlagSet
	)
	if len(args) < 1 || args[0] == "" || args[0] == "help" {
		printHelp(true)
		return nil, nil
	}
	fs.Init("file", flag.ContinueOnError)
	fs.Var(&paths, "path", "see help")
	fs.Var(&names, "name", "see help")
	fs.Var(&sizes, "size", "see help")
	fs.Var(&modes, "mode", "see help")
	fs.Var(&mtimes, "mtime", "see help")
	fs.Var(&contents, "content", "see help")
	fs.Var(&md5s, "md5", "see help")
	fs.Var(&sha1s, "sha1", "see help")
	fs.Var(&sha2s, "sha2", "see help")
	fs.Var(&sha3s, "sha3", "see help")
	fs.Var(&mismatch, "mismatch", "see help")
	fs.Float64Var(&maxdepth, "maxdepth", 1000, "see help")
	fs.Float64Var(&matchlimit, "matchlimit", 1000, "see help")
	fs.BoolVar(&matchall, "matchall", true, "see help")
	fs.BoolVar(&matchany, "matchany", false, "see help")
	fs.BoolVar(&macroal, "macroal", false, "see help")
	fs.BoolVar(&debug, "verbose", false, "see help")
	fs.BoolVar(&returnsha256, "returnsha256", false, "see help")
	fs.BoolVar(&decompress, "decompress", false, "see help")
	err = fs.Parse(args)
	if err != nil {
		return nil, err
	}
	var s search
	s.Paths = paths
	s.Names = names
	s.Sizes = sizes
	s.Modes = modes
	s.Mtimes = mtimes
	s.Contents = contents
	s.MD5 = md5s
	s.SHA1 = sha1s
	s.SHA2 = sha2s
	s.SHA3 = sha3s
	s.Options.MaxDepth = maxdepth
	s.Options.MatchLimit = matchlimit
	s.Options.Macroal = macroal
	s.Options.Mismatch = mismatch
	s.Options.MatchAll = matchall
	s.Options.ReturnSHA256 = returnsha256
	s.Options.Decompress = decompress
	if matchany {
		s.Options.MatchAll = false
	}
	if verbose {
		s.Options.Debug = "print"
	}
	p := newParameters()
	p.Searches["s1"] = s
	r.Parameters = *p
	return r.Parameters, r.ValidateParameters()
}
開發者ID:tomzhang,項目名稱:mig,代碼行數:69,代碼來源:paramscreator.go

示例8: ParamsParser

// ParamsParser implements a command line parameters parser that takes a string
// and returns a Parameters structure in an interface. It will display the module
// help if the arguments string spell the work 'help'
func (r *run) ParamsParser(args []string) (interface{}, error) {
	var (
		err error
		paths, names, sizes, modes, mtimes, contents, md5s, sha1s, sha256s,
		sha384s, sha512s, sha3_224s, sha3_256s, sha3_384s, sha3_512s flagParam
		maxdepth, matchlimit float64
		matchall, matchany   bool
		fs                   flag.FlagSet
	)
	if len(args) < 1 || args[0] == "" || args[0] == "help" {
		printHelp(true)
		return nil, nil
	}
	fs.Init("file", flag.ContinueOnError)
	fs.Var(&paths, "path", "see help")
	fs.Var(&names, "name", "see help")
	fs.Var(&sizes, "size", "see help")
	fs.Var(&modes, "mode", "see help")
	fs.Var(&mtimes, "mtime", "see help")
	fs.Var(&contents, "content", "see help")
	fs.Var(&md5s, "md5", "see help")
	fs.Var(&sha1s, "sha1", "see help")
	fs.Var(&sha256s, "sha256", "see help")
	fs.Var(&sha384s, "sha384", "see help")
	fs.Var(&sha512s, "sha512", "see help")
	fs.Var(&sha3_224s, "sha3_224", "see help")
	fs.Var(&sha3_256s, "sha3_256", "see help")
	fs.Var(&sha3_384s, "sha3_384", "see help")
	fs.Var(&sha3_512s, "sha3_512", "see help")
	fs.Float64Var(&maxdepth, "maxdepth", 0, "see help")
	fs.Float64Var(&matchlimit, "matchlimit", 0, "see help")
	fs.BoolVar(&matchall, "matchall", true, "see help")
	fs.BoolVar(&matchany, "matchany", false, "see help")
	err = fs.Parse(args)
	if err != nil {
		return nil, err
	}
	var s search
	s.Paths = paths
	s.Names = names
	s.Sizes = sizes
	s.Modes = modes
	s.Mtimes = mtimes
	s.Contents = contents
	s.MD5 = md5s
	s.SHA1 = sha1s
	s.SHA256 = sha256s
	s.SHA384 = sha384s
	s.SHA512 = sha512s
	s.SHA3_224 = sha3_224s
	s.SHA3_256 = sha3_256s
	s.SHA3_384 = sha3_384s
	s.SHA3_512 = sha3_512s
	s.Options.MaxDepth = maxdepth
	s.Options.MatchLimit = matchlimit
	s.Options.MatchAll = matchall
	if matchany {
		s.Options.MatchAll = false
	}
	p := newParameters()
	p.Searches["s1"] = s
	r.Parameters = *p
	return r.Parameters, r.ValidateParameters()
}
開發者ID:jvehent,項目名稱:mig,代碼行數:67,代碼來源:paramscreator.go


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