当前位置: 首页>>代码示例>>Golang>>正文


Golang FlagSet.Lookup方法代码示例

本文整理汇总了Golang中flag.FlagSet.Lookup方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.Lookup方法的具体用法?Golang FlagSet.Lookup怎么用?Golang FlagSet.Lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flag.FlagSet的用法示例。


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

示例1: ParseConfig

// ParseConfig parses a config file, using the provided FlagSet to
// look up, parse, and store values.
func ParseConfig(flags *flag.FlagSet, f io.Reader) error {
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())
		if line == "" || strings.HasPrefix(line, "#") {
			continue
		}

		bits := strings.SplitN(line, "=", 2)
		if len(bits) != 2 {
			return fmt.Errorf("illegal config line: `%s'", line)
		}

		key := strings.TrimSpace(bits[0])
		value := strings.TrimSpace(bits[1])

		if flag := flags.Lookup(key); flag == nil {
			return fmt.Errorf("unknown option `%s'", key)
		}

		if err := flags.Set(key, value); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:nelhage,项目名称:go.cli,代码行数:28,代码来源:config.go

示例2: lookupGeneric

func lookupGeneric(name string, set *flag.FlagSet) interface{} {
	f := set.Lookup(name)
	if f != nil {
		return f.Value
	}
	return nil
}
开发者ID:CowLeo,项目名称:gopm,代码行数:7,代码来源:context.go

示例3: normalizeFlags

func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
	visited := make(map[string]bool)
	set.Visit(func(f *flag.Flag) {
		visited[f.Name] = true
	})
	for _, f := range flags {
		parts := strings.Split(f.getName(), ",")
		if len(parts) == 1 {
			continue
		}
		var ff *flag.Flag
		for _, name := range parts {
			name = strings.Trim(name, " ")
			if visited[name] {
				if ff != nil {
					return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name)
				}
				ff = set.Lookup(name)
			}
		}
		if ff == nil {
			continue
		}
		for _, name := range parts {
			name = strings.Trim(name, " ")
			if !visited[name] {
				copyFlag(name, ff, set)
			}
		}
	}
	return nil
}
开发者ID:CowLeo,项目名称:gopm,代码行数:32,代码来源:context.go

示例4: lookupString

func (c *Context) lookupString(name string, set *flag.FlagSet) string {
	f := set.Lookup(name)
	if f != nil {
		return f.Value.String()
	} else {
		return ""
	}
}
开发者ID:jalons,项目名称:cli,代码行数:8,代码来源:context.go

示例5: lookupString

func lookupString(name string, set *flag.FlagSet) string {
	f := set.Lookup(name)
	if f != nil {
		return f.Value.String()
	}

	return ""
}
开发者ID:CowLeo,项目名称:gopm,代码行数:8,代码来源:context.go

示例6: getVal

//Retrieves the argument from the provided flagset with the give name
func getVal(set *flag.FlagSet, arg string) interface{} {
	requestedFlag := set.Lookup(arg)
	if requestedFlag == nil {
		logrus.Debugf("Could not find requested flag: %s", arg)
		return nil
	}
	return requestedFlag.Value.(flag.Getter).Get()
}
开发者ID:aweiteka,项目名称:nulecule-go,代码行数:9,代码来源:command.go

示例7: DebugAddress

func DebugAddress(flags *flag.FlagSet) string {
	dbgFlag := flags.Lookup(DebugFlag)
	if dbgFlag == nil {
		return ""
	}

	return dbgFlag.Value.String()
}
开发者ID:qinguoan,项目名称:vulcan,代码行数:8,代码来源:server.go

示例8: lookupIntSlice

func lookupIntSlice(name string, set *flag.FlagSet) []int {
	f := set.Lookup(name)
	if f != nil {
		return (f.Value.(*IntSlice)).Value()

	}

	return nil
}
开发者ID:CowLeo,项目名称:gopm,代码行数:9,代码来源:context.go

示例9: lookupStringSlice

func lookupStringSlice(name string, set *flag.FlagSet) []string {
	f := set.Lookup(name)
	if f != nil {
		return (f.Value.(*StringSlice)).Value()

	}

	return nil
}
开发者ID:CowLeo,项目名称:gopm,代码行数:9,代码来源:context.go

示例10: FlagVisited

// FlagVisited determines whether the named flag has been visited in the FlagSet
// given. This is helpful if you want to have a flag that triggers an action
// when given, but is not a boolean flag.
func FlagVisited(name string, flags flag.FlagSet) (didFind bool) {
	toFind := flags.Lookup(name)

	flags.Visit(func(f *flag.Flag) {
		if f == toFind {
			didFind = true
		}
	})

	return
}
开发者ID:hawx,项目名称:img,代码行数:14,代码来源:utils.go

示例11: lookupBoolT

func lookupBoolT(name string, set *flag.FlagSet) bool {
	f := set.Lookup(name)
	if f != nil {
		parsed, err := strconv.ParseBool(f.Value.String())
		if err != nil {
			return false
		}
		return parsed
	}
	return false
}
开发者ID:otsimo,项目名称:catalog,代码行数:11,代码来源:flag_generated.go

示例12: lookupDuration

func lookupDuration(name string, set *flag.FlagSet) time.Duration {
	f := set.Lookup(name)
	if f != nil {
		val, err := time.ParseDuration(f.Value.String())
		if err == nil {
			return val
		}
	}

	return 0
}
开发者ID:CowLeo,项目名称:gopm,代码行数:11,代码来源:context.go

示例13: lookupStringSlice

func lookupStringSlice(name string, set *flag.FlagSet) []string {
	f := set.Lookup(name)
	if f != nil {
		parsed, err := (f.Value.(*StringSlice)).Value(), error(nil)
		if err != nil {
			return nil
		}
		return parsed
	}
	return nil
}
开发者ID:otsimo,项目名称:catalog,代码行数:11,代码来源:flag_generated.go

示例14: lookupString

func lookupString(name string, set *flag.FlagSet) string {
	f := set.Lookup(name)
	if f != nil {
		parsed, err := f.Value.String(), error(nil)
		if err != nil {
			return ""
		}
		return parsed
	}
	return ""
}
开发者ID:otsimo,项目名称:catalog,代码行数:11,代码来源:flag_generated.go

示例15: lookupInt64

func lookupInt64(name string, set *flag.FlagSet) int64 {
	f := set.Lookup(name)
	if f != nil {
		parsed, err := strconv.ParseInt(f.Value.String(), 0, 64)
		if err != nil {
			return 0
		}
		return parsed
	}
	return 0
}
开发者ID:otsimo,项目名称:catalog,代码行数:11,代码来源:flag_generated.go


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