• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang common.Die函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/coreos/rkt/tools/common.Die函数的典型用法代码示例。如果您正苦于以下问题:Golang Die函数的具体用法?Golang Die怎么用?Golang Die使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: goGetArgs

// getArgs parses given parameters and returns target, repo, module and
// mode. If mode is "files", then target is optional.
func goGetArgs(args []string) (string, string, string, goDepsMode) {
	f, target := standardFlags(goCmd)
	repo := f.String("repo", "", "Go repo (example: github.com/coreos/rkt)")
	module := f.String("module", "", "Module inside Go repo (example: stage1)")
	mode := f.String("mode", "make", "Mode to use (make - print deps as makefile [default], files - print a list of files)")

	f.Parse(args)
	if *repo == "" {
		common.Die("--repo parameter must be specified and cannot be empty")
	}
	if *module == "" {
		common.Die("--module parameter must be specified and cannot be empty")
	}

	var dMode goDepsMode

	switch *mode {
	case "make":
		dMode = goMakeMode
		if *target == "" {
			common.Die("--target parameter must be specified and cannot be empty when using 'make' mode")
		}
	case "files":
		dMode = goFilesMode
	default:
		common.Die("unknown --mode parameter %q - expected either 'make' or 'files'", *mode)
	}
	return *target, *repo, *module, dMode
}
开发者ID:matomesc,项目名称:rkt,代码行数:31,代码来源:gocmd.go


示例2: globGetArgs

// globGetArgs parses given parameters and returns a target, a suffix
// and a list of files.
func globGetArgs(args []string) globArgs {
	f, target := standardFlags(globCmd)
	suffix := f.String("suffix", "", "File suffix (example: .go)")
	globbingMode := f.String("glob-mode", "all", "Which files to glob (normal, dot-files, all [default])")
	filelist := f.String("filelist", "", "Read all the files from this file")
	var mapTo []string
	mapToWrapper := common.StringSliceWrapper{Slice: &mapTo}
	f.Var(&mapToWrapper, "map-to", "Map contents of filelist to this directory, can be used multiple times")

	f.Parse(args)
	if *target == "" {
		common.Die("--target parameter must be specified and cannot be empty")
	}
	mode := globModeFromString(*globbingMode)
	if *filelist == "" {
		common.Die("--filelist parameter must be specified and cannot be empty")
	}
	if len(mapTo) < 1 {
		common.Die("--map-to parameter must be specified at least once")
	}
	return globArgs{
		target:   *target,
		suffix:   *suffix,
		mode:     mode,
		filelist: *filelist,
		mapTo:    mapTo,
	}
}
开发者ID:matomesc,项目名称:rkt,代码行数:30,代码来源:globcmd.go


示例3: getValidArgs

func getValidArgs() (string, []string) {
	filename := ""
	mapTo := []string{}
	mapToWrapper := common.StringSliceWrapper{
		Slice: &mapTo,
	}

	flag.StringVar(&filename, "filelist", "", "Name of the source (path to the directory or to the filelist")
	flag.Var(&mapToWrapper, "map-to", "Map contents of traversed source to this directory, can be used multiple times")

	flag.Parse()
	if filename == "" {
		common.Die("No --filelist parameter passed")
	}
	if len(mapTo) < 1 {
		common.Die("No --map-to parameter passed, at least one is required")
		os.Exit(1)
	}

	filename = common.MustAbs(filename)
	for i := 0; i < len(mapTo); i++ {
		mapTo[i] = common.MustAbs(mapTo[i])
	}
	return filename, mapTo
}
开发者ID:NeilW,项目名称:rkt,代码行数:25,代码来源:main.go


示例4: getListing

func getListing(filename string) *filelist.Lists {
	fl, err := os.Open(filename)
	if err != nil {
		common.Die("Failed to open filelist %q: %v", filename, err)
	}
	defer fl.Close()

	list := &filelist.Lists{}
	if err := list.ParseFilelist(fl); err != nil {
		common.Die("Error during getting listing from filelist %q: %v\n", filename, err)
	}
	return list
}
开发者ID:NeilW,项目名称:rkt,代码行数:13,代码来源:main.go


示例5: goGetFiles

// goGetFiles returns a list of files that are in given packages. File
// paths are relative to a given directory.
func goGetFiles(dir string, pkgs []string) []string {
	params := []string{
		"Dir",
		"GoFiles",
		"CgoFiles",
	}
	var allFiles []string
	rawTuples := goRun(goList(params, pkgs))
	for _, raw := range rawTuples {
		tuple := goSliceRawTuple(raw)
		moduleDir := filepath.Clean(tuple[0])
		dirSep := fmt.Sprintf("%s%c", dir, filepath.Separator)
		moduleDirSep := fmt.Sprintf("%s%c", moduleDir, filepath.Separator)
		if !strings.HasPrefix(moduleDirSep, dirSep) {
			continue
		}
		relModuleDir, err := filepath.Rel(dir, moduleDir)
		if err != nil {
			common.Die("Could not make a relative path from %q to %q, even if they have the same prefix", moduleDir, dir)
		}
		files := append(goSliceRawSlice(tuple[1]), goSliceRawSlice(tuple[2])...)
		for i := 0; i < len(files); i++ {
			files[i] = filepath.Join(relModuleDir, files[i])
		}
		allFiles = append(allFiles, files...)
	}
	return allFiles
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:30,代码来源:gocmd.go


示例6: globGetFiles

func globGetFiles(args globArgs) []string {
	f, err := globGetFilesFromFilelist(args.filelist)
	if err != nil {
		common.Die("Failed to get files from filelist %q: %v", args.filelist, err)
	}
	return common.MapFilesToDirectories(f, args.mapTo)
}
开发者ID:matomesc,项目名称:rkt,代码行数:7,代码来源:globcmd.go


示例7: main

func main() {
	depTypes := getAllDepTypes()
	depTypesString := fmt.Sprintf("'%s'", strings.Join(depTypes, "', '"))
	if len(os.Args) < 2 {
		common.Die("Expected a deps type (possible values: %s)", depTypesString)
	}
	depType := os.Args[1]
	cmdArgs := os.Args[2:]
	if f, ok := cmds[depType]; ok {
		fmt.Print(f(cmdArgs))
	} else if depType == "--help" || depType == "-help" {
		common.Warn("Run %s with one of the following commands: %s\nE.g. %s %s --help", appName(), depTypesString, os.Args[0], depTypes[0])
	} else {
		common.Die("Unknown deps type: %q, expected one of %s", depType, depTypesString)
	}
}
开发者ID:matomesc,项目名称:rkt,代码行数:16,代码来源:main.go


示例8: getDeepListing

func getDeepListing(dir string) *filelist.Lists {
	walker := newFsWalker(common.MustAbs(dir))
	list, err := walker.getListing()
	if err != nil {
		common.Die("Error during getting listing from directory %q: %v", dir, err)
	}
	return list
}
开发者ID:matomesc,项目名称:rkt,代码行数:8,代码来源:main.go


示例9: kvGetArgs

func kvGetArgs(args []string) (string, map[string]string) {
	f, target := standardFlags(kvCmd)

	f.Parse(args)
	if *target == "" {
		common.Die("--target parameter must be specified and cannot be empty")
	}
	return *target, toMap(f.Args()...)
}
开发者ID:matomesc,项目名称:rkt,代码行数:9,代码来源:kvcmd.go


示例10: getShallowListing

func getShallowListing(dir, suffix string) *filelist.Lists {
	list := &filelist.Lists{}
	fiList, err := ioutil.ReadDir(dir)
	if err != nil {
		common.Die("Failed to read directory %q: %v", dir, err)
	}
	for _, fi := range fiList {
		name := fi.Name()
		if !strings.HasSuffix(name, suffix) {
			continue
		}
		if strings.HasPrefix(name, ".") {
			continue
		}
		if err := categorizeEntry(name, fi.Mode(), list); err != nil {
			common.Die("%v", err)
		}
	}
	return list
}
开发者ID:matomesc,项目名称:rkt,代码行数:20,代码来源:main.go


示例11: globGetArgs

// globGetArgs parses given parameters and returns a target, a suffix
// and a list of files.
func globGetArgs(args []string) globArgs {
	f, target := standardFlags(globCmd)
	suffix := f.String("suffix", "", "File suffix (example: .go)")
	globbingMode := f.String("glob-mode", "all", "Which files to glob (normal, dot-files, all [default])")
	filesMode := f.String("mode", "args", "How to get files, either 'filelist' mode or 'args' [default]")
	filelist := f.String("filelist", "", "For filelist mode, read all the files from this file")
	mapTo := []string{}
	mapToWrapper := common.StringSliceWrapper{Slice: &mapTo}
	f.Var(&mapToWrapper, "map-to", "Map contents of filelist to this directory, can be used multiple times")

	f.Parse(args)
	if *target == "" {
		common.Die("--target parameter must be specified and cannot be empty")
	}
	mode := globModeFromString(*globbingMode)
	switch *filesMode {
	case "filelist":
		if *filelist == "" {
			common.Die("--filelist parameter must be specified and cannot be empty")
		}
		if len(mapTo) < 1 {
			common.Die("--map-to parameter must be specified at least once")
		}
	case "args":
		if *filelist != "" {
			common.Warn("--filelist parameter is ignored in args mode")
		}
		if len(mapTo) > 0 {
			common.Warn("--map-to parameter is ignored in args mode")
		}
	}
	return globArgs{
		target:   *target,
		suffix:   *suffix,
		files:    f.Args(),
		mode:     mode,
		fMode:    *filesMode,
		filelist: *filelist,
		mapTo:    mapTo,
	}
}
开发者ID:harpe1999,项目名称:rkt,代码行数:43,代码来源:globcmd.go


示例12: getItems

func getItems() []items {
	kinds := []*kindData{
		&kindData{
			option: "files",
			proc:   &fileProcessor{},
		},
		&kindData{
			option: "symlinks",
			proc:   &symlinkProcessor{},
		},
		&kindData{
			option: "dirs",
			proc:   &dirProcessor{},
		},
	}

	for _, k := range kinds {
		flag.StringVar(&k.filename, k.option, "", fmt.Sprintf("List of %s", k.option))
	}
	flag.Parse()
	for _, k := range kinds {
		if k.filename == "" {
			common.Die("No --%s parameter passed", k.option)
		}
	}

	allItems := make([]items, 0, len(kinds))
	for _, k := range kinds {
		l, err := getList(k.filename, k.proc)
		if err != nil {
			common.Die("Failed to get %s list: %v", k.proc.kind(), err)
		}
		allItems = append(allItems, items{
			kind: k.proc.kind(),
			list: l,
		})
	}

	return allItems
}
开发者ID:NeilW,项目名称:rkt,代码行数:40,代码来源:main.go


示例13: globModeFromString

func globModeFromString(mode string) globMode {
	switch mode {
	case "normal":
		return globNormal
	case "dot-files":
		return globDotFiles
	case "all":
		return globAll
	default:
		common.Die("Unknown glob mode %q", mode)
	}
	panic("Should not happen")
}
开发者ID:matomesc,项目名称:rkt,代码行数:13,代码来源:globcmd.go


示例14: toMap

// toMap creates a map from passed strings. This function expects an
// even number of strings, otherwise it will bail out. Odd (first,
// third and so on) strings are keys, even (second, fourth and so on)
// strings are values.
func toMap(kv ...string) map[string]string {
	if len(kv)%2 != 0 {
		common.Die("Expected even number of strings in toMap")
	}
	r := make(map[string]string, len(kv))
	lastKey := ""
	for i, kv := range kv {
		if i%2 == 0 {
			lastKey = kv
		} else {
			r[lastKey] = kv
		}
	}
	return r
}
开发者ID:matomesc,项目名称:rkt,代码行数:19,代码来源:util.go


示例15: goRun

// goRun executes given argument list and captures its output. The
// output is sliced into lines with empty lines being discarded.
func goRun(argv []string) []string {
	cmd := exec.Command(argv[0], argv[1:]...)
	stdout := new(bytes.Buffer)
	stderr := new(bytes.Buffer)
	cmd.Stdout = stdout
	cmd.Stderr = stderr
	if err := cmd.Run(); err != nil {
		common.Die("Error running %s: %v: %s", strings.Join(argv, " "), err, stderr.String())
	}
	rawLines := strings.Split(stdout.String(), "\n")
	lines := make([]string, 0, len(rawLines))
	for _, line := range rawLines {
		if trimmed := strings.TrimSpace(line); trimmed != "" {
			lines = append(lines, trimmed)
		}
	}
	return lines
}
开发者ID:matomesc,项目名称:rkt,代码行数:20,代码来源:gocmd.go


示例16: goGetDeps

// goGetDeps gets the directory of a given repo and the all
// dependencies, direct or indirect, of a given module in the repo.
func goGetDeps(repo, module string) (string, []string) {
	pkg := path.Join(repo, module)
	rawTuples := goRun(goList([]string{"Dir", "Deps"}, []string{pkg}))
	if len(rawTuples) != 1 {
		common.Die("Expected to get only one line from go list for a single package")
	}
	tuple := goSliceRawTuple(rawTuples[0])
	dir := tuple[0]
	if module != "." {
		dirsToStrip := 1 + strings.Count(module, "/")
		for i := 0; i < dirsToStrip; i++ {
			dir = filepath.Dir(dir)
		}
	}
	dir = filepath.Clean(dir)
	deps := goSliceRawSlice(tuple[1])
	return dir, append([]string{pkg}, deps...)
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:20,代码来源:gocmd.go



注:本文中的github.com/coreos/rkt/tools/common.Die函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.UnsupportedError函数代码示例发布时间:2022-05-23
下一篇:
Golang aci-server.Server类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap