本文整理汇总了Golang中flag.Visit函数的典型用法代码示例。如果您正苦于以下问题:Golang Visit函数的具体用法?Golang Visit怎么用?Golang Visit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Visit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
finished := make(chan bool)
joblist := newJoblist(finished)
useCmdFile := false
useCmdPort := false
markFlags := func(f *flag.Flag) {
if f.Name == "cmdport" {
useCmdPort = true
} else if f.Name == "cmdfile" {
useCmdFile = true
}
}
flag.Visit(markFlags)
startWorkers(joblist)
if useCmdFile {
postCommandsFromFile(joblist, useCmdPort)
}
if !useCmdFile || useCmdPort {
go startAdders(joblist)
}
<-finished
logfile.Printf("%d jobs succeeded\n", joblist.nok)
logfile.Printf("%d jobs failed\n", joblist.nfail)
logfile.Printf("%d jobs completed\n", joblist.nok+joblist.nfail)
}
开发者ID:velour,项目名称:distribute,代码行数:30,代码来源:main.go
示例2: Parse
func Parse() {
if *configFile == "" {
return
}
config := readConfig()
explicit := make([]*flag.Flag, 0)
all := make([]*flag.Flag, 0)
flag.Visit(func(f *flag.Flag) {
explicit = append(explicit, f)
})
flag.VisitAll(func(f *flag.Flag) {
all = append(all, f)
if !contains(explicit, f) {
val := config[f.Name]
if val != "" {
err := f.Value.Set(val)
if err != nil {
log.Fatalf("Failed to set flag %s with value %s", f.Name, val)
}
}
}
})
Outer:
for name, val := range config {
for _, f := range all {
if f.Name == name {
continue Outer
}
}
log.Fatalf("Unknown flag %s=%s in config file.", name, val)
}
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:32,代码来源:flagconfig.go
示例3: Save
// Save set options to a configuration file. If categories are given, only those
// options in one of the categories is saved.
func Save(path, comment string, category ...string) error {
file, err := util.CreatePath(path, 0777, 0777)
if err != nil {
return err
}
defer file.Close()
set := make(map[string]bool)
flag.Visit(func(f *flag.Flag) {
set[f.Name] = true
})
for _, s := range strings.Split(comment, "\n") {
fmt.Fprintf(file, "# %s\n", s)
}
fmt.Fprintf(file, "# Generated on %s\n", time.Now())
for _, opt := range Options {
f := flag.Lookup(opt.Name)
if !opt.Relevant(category...) || f == nil {
continue
}
fmt.Fprintf(file, "\n# %s\n", opt.Help)
if set[opt.Name] {
fmt.Fprintf(file, "%s = %v\n", opt.Name, f.Value)
} else {
fmt.Fprintf(file, "# %s = %v\n", opt.Name, f.Value)
}
}
return nil
}
开发者ID:kevinawalsh,项目名称:cloudproxy,代码行数:33,代码来源:options.go
示例4: parse
func parse() (err error) {
// Record which flags were set by command line args so that we don't overwrite them.
set := make(map[*flag.Flag]bool, 0)
flag.Visit(func(f *flag.Flag) {
set[f] = true
})
flag.VisitAll(func(f *flag.Flag) {
if !set[f] && err == nil {
r := strings.NewReplacer(".", "_", "-", "_")
name := r.Replace(f.Name)
if UseUpperCaseFlagNames {
name = strings.ToUpper(name)
}
val := os.Getenv(name)
if val != "" {
if seterr := f.Value.Set(val); seterr != nil {
err = fmt.Errorf("Failed to set flag %s with value %s", f.Name, val)
}
}
}
})
return
}
开发者ID:josharian,项目名称:go.flagenv,代码行数:25,代码来源:flagenv.go
示例5: getMissingFlags
func getMissingFlags() []string {
var (
set, missing []string
found = false
)
// Visit only the flags that have been set
flag.Visit(func(f *flag.Flag) {
set = append(set, f.Name)
})
// Visit all the flags, even those not set
flag.VisitAll(func(f *flag.Flag) {
for _, v := range set {
if v == f.Name {
found = true
break
}
}
// If we don't find the flag in the slice of already set flags, we add it to the missing slice
if !found {
missing = append(missing, f.Name)
}
found = false
})
return missing
}
开发者ID:vaz-ar,项目名称:cfgFlags,代码行数:25,代码来源:cfgFlags.go
示例6: configure
func configure(flags ServerConfig) {
if flag.NArg() == 1 {
fname := flag.Arg(0)
f, err := os.Open(fname)
if err != nil {
log.Fatalf("Config reading error: %s\n", err.String())
}
dec := json.NewDecoder(f)
err = dec.Decode(&server)
if err != nil {
log.Fatalf("Config parsing error: %s\n", err.String())
}
action = "serve"
}
flag.Visit(func(flag *flag.Flag) {
switch flag.Name {
case "version":
action = "version"
case "port":
server.Port = flags.Port
case "host":
server.Host = flags.Host
case "tls-cert":
server.TLSCertFile = flags.TLSCertFile
case "tls-key":
server.TLSKeyFile = flags.TLSKeyFile
case "log":
server.Log = flags.Log
}
})
}
开发者ID:andradeandrey,项目名称:webrocket,代码行数:31,代码来源:main.go
示例7: loadConfig
func loadConfig(nm string, flagSet *flag.FlagSet, isOverride bool) error {
f, e := os.Open(nm)
if nil != e {
return fmt.Errorf("load config '%s' failed, %v", nm, e)
}
var res map[string]interface{}
e = json.NewDecoder(f).Decode(&res)
if nil != e {
return fmt.Errorf("load config '%s' failed, %v", nm, e)
}
actual := map[string]string{}
fn := func(f *flag.Flag) {
actual[f.Name] = f.Name
}
if nil == flagSet {
flag.Visit(fn)
} else {
flagSet.Visit(fn)
}
e = assignFlagSet("", res, flagSet, actual, isOverride)
if nil != e {
return fmt.Errorf("load config '%s' failed, %v", nm, e)
}
return nil
}
开发者ID:runner-mei,项目名称:delayed_job,代码行数:28,代码来源:config.go
示例8: parse
// parse() iterates through the flags and populate the
// values from environment variables if present
func parse(prefix string) (errp error) {
cmdline := make(map[string]bool)
flag.Visit(func(f *flag.Flag) {
cmdline[f.Name] = true
})
flag.VisitAll(func(f *flag.Flag) {
if _, ok := cmdline[f.Name]; !ok {
val := os.Getenv(getEnvName(prefix, f.Name))
if val != "" {
err := f.Value.Set(val)
if err != nil {
if errp != nil {
errp = fmt.Errorf(errp.Error()+", value:\"%s\" for flag:\"%s\"", val, f.Name)
} else {
errp = fmt.Errorf(":envtoflag: error setting value:\"%s\" for flag:\"%s\"", val, f.Name)
}
}
}
}
})
return
}
开发者ID:PayPal-OpportunityHack-BLR-2015,项目名称:bloodcare-hifx,代码行数:28,代码来源:envtoflag.go
示例9: FlagMerge
func (flagConf *DBConf) FlagMerge(fileConf *DBConf) (*DBConf, error) {
only := make(map[string]bool, 0)
flag.Visit(func(f *flag.Flag) { only[f.Name] = true })
if only["map-seed-size"] {
return flagConf, fmt.Errorf("The map seed size cannot be changed for " +
"an existing database.")
}
if only["read-only"] {
return flagConf, fmt.Errorf("The read-only setting cannot be changed " +
"for an existing database.")
}
if !only["min-match-len"] {
flagConf.MinMatchLen = fileConf.MinMatchLen
}
if !only["match-kmer-size"] {
flagConf.MatchKmerSize = fileConf.MatchKmerSize
}
if !only["gapped-window-size"] {
flagConf.GappedWindowSize = fileConf.GappedWindowSize
}
if !only["ungapped-window-size"] {
flagConf.UngappedWindowSize = fileConf.UngappedWindowSize
}
if !only["ext-seq-id-threshold"] {
flagConf.ExtSeqIdThreshold = fileConf.ExtSeqIdThreshold
}
if !only["match-seq-id-threshold"] {
flagConf.MatchSeqIdThreshold = fileConf.MatchSeqIdThreshold
}
if !only["match-extend"] {
flagConf.MatchExtend = fileConf.MatchExtend
}
if !only["ext-seed-size"] {
flagConf.ExtSeedSize = fileConf.ExtSeedSize
}
if !only["low-complexity"] {
flagConf.LowComplexity = fileConf.LowComplexity
}
if !only["seed-low-complexity"] {
flagConf.SeedLowComplexity = fileConf.SeedLowComplexity
}
if !only["plain"] {
flagConf.SavePlain = fileConf.SavePlain
}
if !only["read-only"] {
flagConf.ReadOnly = fileConf.ReadOnly
}
if !only["makeblastdb"] {
flagConf.BlastMakeBlastDB = fileConf.BlastMakeBlastDB
}
if !only["diamond"] {
flagConf.Dmnd = fileConf.Dmnd
}
if !only["dbsize"] {
flagConf.BlastDBSize = fileConf.BlastDBSize
}
return flagConf, nil
}
开发者ID:yesimon,项目名称:MICA,代码行数:60,代码来源:dbconf.go
示例10: getTaskArgs
// getTaskArgs returns the arguments to be passed to "gake/tasking".
func getTaskArgs() []string {
args := make([]string, 0)
flag.Visit(func(f *flag.Flag) {
isBoolean := false
switch f.Name {
case "c", "x", "keep": // Flags skipped
return
// Rewrite known flags to have "task" before them
case "cpu", "parallel", "run", "short", "timeout", "v":
f.Name = "task." + f.Name
fallthrough
case "task.short", "task.v":
isBoolean = true
}
args = append(args, "-"+f.Name)
if !isBoolean {
args = append(args, f.Value.String())
}
})
fargs := flag.Args()
if len(fargs) > 1 {
args = append(args, "-task.args")
args = append(args, fargs[1:]...)
}
return args
}
开发者ID:kless,项目名称:gake,代码行数:33,代码来源:flag.go
示例11: init
func init() {
flag.Parse()
// Create a map of pointers to all the current flags
flags := map[string]*flag.Flag{}
flag.VisitAll(func(f *flag.Flag) {
flags[f.Name] = f
})
// Remove the flags that were set on the command line
flag.Visit(func(f *flag.Flag) {
delete(flags, f.Name)
})
// Now for the flags that weren't set on the cli,
// Look at the env for 'PBOX_<uppercase flag name>'
// If it exists, use it to set the corresponding flag.
for _, f := range flags {
var buffer bytes.Buffer
buffer.WriteString("PBOX_")
buffer.WriteString(strings.ToUpper(f.Name))
if os.Getenv(buffer.String()) != "" {
f.Value.Set(os.Getenv(buffer.String()))
}
}
}
开发者ID:nickjones,项目名称:proc_box,代码行数:26,代码来源:main.go
示例12: main
func main() {
flag.Usage = usage
flag.Parse()
proc := lines
flag.Visit(func(f *flag.Flag) {
if f.Name == "c" {
proc = chars
}
})
if flag.NArg() == 0 {
proc(os.Stdin, "<stdin>")
} else {
for _, name := range flag.Args() {
f, err := os.Open(name)
if err != nil {
fmt.Fprintln(os.Stderr, "read:", err)
os.Exit(2)
}
proc(f, name)
f.Close()
}
}
os.Exit(status)
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:27,代码来源:read.go
示例13: run
func run(inFile string, gpu int, webAddr string) {
// overridden flags
gpuFlag := fmt.Sprint(`-gpu=`, gpu)
httpFlag := fmt.Sprint(`-http=`, webAddr)
// pass through flags
flags := []string{gpuFlag, httpFlag}
flag.Visit(func(f *flag.Flag) {
if f.Name != "gpu" && f.Name != "http" && f.Name != "failfast" {
flags = append(flags, fmt.Sprintf("-%v=%v", f.Name, f.Value))
}
})
flags = append(flags, inFile)
cmd := exec.Command(os.Args[0], flags...)
log.Println(os.Args[0], flags)
err := cmd.Run()
if err != nil {
log.Println(inFile, err)
exitStatus.set(1)
numFailed.inc()
if *flag_failfast {
os.Exit(1)
}
} else {
numOK.inc()
}
}
开发者ID:jsampaio,项目名称:3,代码行数:28,代码来源:queue.go
示例14: ConfigureLogging
// ConfigureLogging applies the configuration in revel.Config to the glog flags.
// Logger flags specified explicitly on the command line are not changed.
func ConfigureLogging() {
// Get the flags specified on the command line.
specifiedFlags := make(map[string]struct{})
flag.Visit(func(f *flag.Flag) { specifiedFlags[f.Name] = struct{}{} })
// For each logger option in app.conf..
var err error
for _, option := range Config.Options("log.") {
val, _ := Config.String(option)
switch flagname := option[len("log."):]; flagname {
case "v", "vmodule", "logtostderr", "alsologtostderr", "stderrthreshold", "log_dir":
// If it was specified on the command line, don't set it from app.conf
if _, ok := specifiedFlags[flagname]; ok {
continue
}
// Look up the flag and set it.
// If it's log_dir, make it into an absolute path and creat it if necessary.
if flagname == "log_dir" {
if val, err = filepath.Abs(val); err != nil {
glog.Fatalln("Failed to get absolute path to log_dir:", err)
}
os.MkdirAll(val, 0777) // Create the log dir if it doesn't already exist.
}
if err = flag.Set(flagname, val); err != nil {
glog.Fatalf("Failed to set glog option for %s=%s: %s", flagname, val, err)
}
case "maxsize":
if glog.MaxSize, err = humanize.ParseBytes(val); err != nil {
glog.Fatalf("Failed to parse log.MaxSize=%s: %s", val, err)
}
}
}
}
开发者ID:hongrich,项目名称:revel,代码行数:36,代码来源:revel.go
示例15: Parse
// Parse parses the command-line flags from os.Args[1:] and sets the values in
// this ConfigoSet. Then the configuration file is parsed and any item that
// was not already set by the command line is set. Must be called after all
// configuration options are defined and before conifguration options are
// accessed by the program.
func (c *ConfigoSet) Parse() (err error) {
// Start by parsing the command line with the flag package and then set the
// parsed values into the ConfigoSet.
flag.Parse()
flag.Visit(func(f *flag.Flag) {
c.Set(f.Name, f.Value.String())
})
// Now parse the configuration file, but first create the config file if it
// does not exist. If that's the case we're all done and we can return.
if _, err = os.Stat(c.path); err != nil {
if !os.IsNotExist(err) {
return
}
c.parsed = true
err = c.WriteDefaultConfig(c.path)
return
}
// Parse the config file, but only set the options that didn't appear on
// the command line.
if !c.parsed {
var content []byte
content, err = ioutil.ReadFile(c.path)
if err != nil {
return
}
for i, line := range strings.Split(string(content), "\n") {
line = strings.TrimSpace(line)
if len(line) > 0 && !strings.HasPrefix(line, "#") {
var name, value string
fields := strings.SplitN(line, c.delimiter, 2)
if len(fields) != 2 {
errors.New(fmt.Sprintf("Invalid key%svalue pair in conifiguration file %s on line %d.\n", c.delimiter, c.path, i))
}
name = strings.TrimSpace(fields[0])
value = strings.TrimSpace(fields[1])
// Check if the item was already set from the command line.
if _, exists := c.actual[name]; !exists {
// Is this even a valid config item?
config := c.Lookup(name)
if config == nil {
panic(errors.New("unknown configuration item"))
}
c.Set(name, value)
}
}
}
c.parsed = true
}
return
}
开发者ID:quincy,项目名称:configo,代码行数:64,代码来源:configo.go
示例16: WhoCame
func WhoCame() []*flag.Flag {
var res []*flag.Flag
visit := func(f *flag.Flag) {
res = append(res, f)
}
flag.Visit(visit)
return res
}
开发者ID:ArthurZagidullin,项目名称:activecis,代码行数:8,代码来源:first.go
示例17: main
func main() {
var err error
flag.Parse()
fmt.Println("conquest", "v"+conquest.VERSION, "\n")
if _, err := os.Stat(configfile); os.IsNotExist(err) {
fmt.Println(configfile, "file not found")
os.Exit(1)
}
conq, err := conquest.RunScript(configfile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
flag.Visit(func(f *flag.Flag) {
switch f.Name {
case "u":
conq.TotalUsers = users
case "t":
var duration time.Duration
duration, err = time.ParseDuration(timeout)
if err == nil {
conq.Duration = duration
}
case "s":
conq.Sequential = sequential
}
})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("performing transactions...\n")
var fo *os.File
if output == "" {
fo = os.Stdout
} else {
fo, err = os.Create(output)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
reporter := conquest.NewReporter(fo, verbose)
err = conquest.Perform(conq, reporter)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
<-reporter.C.Done
}
开发者ID:rizqi101,项目名称:conquest,代码行数:58,代码来源:main.go
示例18: NewReceiver
func (rcvr *Receiver) NewReceiver() {
switch strings.ToLower(*msgType) {
case "scm":
rcvr.p = scm.NewParser(*symbolLength, *fastMag)
case "idm":
rcvr.p = idm.NewParser(*symbolLength, *fastMag)
case "r900":
rcvr.p = r900.NewParser(*symbolLength, *fastMag)
default:
log.Fatalf("Invalid message type: %q\n", *msgType)
}
if !*quiet {
rcvr.p.Cfg().Log()
}
// Connect to rtl_tcp server.
if err := rcvr.Connect(nil); err != nil {
log.Fatal(err)
}
rcvr.HandleFlags()
// Tell the user how many gain settings were reported by rtl_tcp.
if !*quiet {
log.Println("GainCount:", rcvr.SDR.Info.GainCount)
}
centerfreqFlagSet := false
sampleRateFlagSet := false
gainFlagSet := false
flag.Visit(func(f *flag.Flag) {
switch f.Name {
case "centerfreq":
centerfreqFlagSet = true
case "samplerate":
sampleRateFlagSet = true
case "gainbyindex", "tunergainmode", "tunergain", "agcmode":
gainFlagSet = true
}
})
// Set some parameters for listening.
if centerfreqFlagSet {
rcvr.SetCenterFreq(uint32(rcvr.Flags.CenterFreq))
} else {
rcvr.SetCenterFreq(rcvr.p.Cfg().CenterFreq)
}
if !sampleRateFlagSet {
rcvr.SetSampleRate(uint32(rcvr.p.Cfg().SampleRate))
}
if !gainFlagSet {
rcvr.SetGainMode(true)
}
return
}
开发者ID:purpleidea,项目名称:rtlamr,代码行数:58,代码来源:recv.go
示例19: flagIsSet
func flagIsSet(name string) bool {
set := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
set = true
}
})
return set
}
开发者ID:wwalexander,项目名称:doddns,代码行数:9,代码来源:server.go
示例20: hasflag
func hasflag(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}
开发者ID:ynkdir,项目名称:x-go-diff,代码行数:9,代码来源:diff.go
注:本文中的flag.Visit函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论