當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。