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

Golang cli.Fatalf函数代码示例

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

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



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

示例1: execute

func (C *CMD) execute() (code int, err error) {
	c := exec.Command(C.Name, C.Args...)
	c.Stdout = C.Stdout
	c.Stderr = C.Stderr
	c.Env = os.Environ()
	if C.EchoStdout {
		c.Stdout = io.MultiWriter(os.Stdout, c.Stdout)
	}
	if C.EchoStderr {
		c.Stderr = io.MultiWriter(os.Stderr, c.Stderr)
	}
	if C.WriteStdout != nil {
		c.Stdout = io.MultiWriter(C.WriteStdout, c.Stdout)
	}
	if C.WriteStderr != nil {
		c.Stderr = io.MultiWriter(C.WriteStderr, c.Stderr)
	}
	if C.EchoStdout || C.EchoStderr {
		cli.Logf("shell> %s", C)
	}
	if err := c.Start(); err != nil {
		cli.Fatalf("Unable to begin command execution; %s", err)
	}
	err = c.Wait()
	if err != nil {
		if exiterr, ok := err.(*exec.ExitError); ok {
			if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
				return status.ExitStatus(), err
			}
		}
		cli.Fatalf("Command failed, unable to get exit code: %s", C)
	}
	return 0, nil
}
开发者ID:liamjbennett,项目名称:sous,代码行数:34,代码来源:cmd.go


示例2: AssembleTargetContext

func (s *Sous) AssembleTargetContext(targetName string) (Target, *Context) {
	packs := s.Packs
	p := DetectProjectType(packs)
	if p == nil {
		cli.Fatalf("no buildable project detected")
	}
	pack := CompiledPack{Pack: p}
	target, ok := pack.GetTarget(targetName)
	if !ok {
		cli.Fatalf("The %s build pack does not support %s", pack, targetName)
	}
	if fatal := CheckForProblems(pack.Pack); fatal {
		cli.Fatal()
	}
	context := GetContext(targetName)
	err := target.Check()
	if err != nil {
		cli.Fatalf("unable to %s %s project: %s", targetName, pack, err)
	}
	// If the pack specifies a version, check it matches the tagged version
	packAppVersion := strings.Split(pack.AppVersion(), "+")[0]
	if packAppVersion != "" {
		pv := version.Version(packAppVersion)
		gv := version.Version(context.BuildVersion.MajorMinorPatch)
		if !pv.Version.LimitedEqual(gv.Version) {
			cli.Warn("using latest git tagged version %s; your code reports version %s, which is ignored", gv, pv)
		}
	}
	return target, context
}
开发者ID:liamjbennett,项目名称:sous,代码行数:30,代码来源:assembly.go


示例3: Contracts

func Contracts(sous *core.Sous, args []string) {
	contractsFlags.Parse(args)
	args = contractsFlags.Args()
	timeout := *timeoutFlag
	targetName := "app"
	if len(args) != 0 {
		targetName = args[0]
	}
	core.RequireGit()
	core.RequireDocker()

	if *dockerImage != "" {
		cli.Fatalf("-image flag not yet implemented")
	}

	target, context := sous.AssembleTargetContext(targetName)

	sous.RunTarget(target, context)

	cli.Logf("=> Running Contracts")
	cli.Logf(`=> **TIP:** Open another terminal in this directory and type **sous logs -f**`)

	taskHost := core.DivineTaskHost()
	port0, err := ports.GetFreePort()
	if err != nil {
		cli.Fatalf("Unable to get free port: %s", err)
	}

	dr := docker.NewRun(context.DockerTag())
	dr.AddEnv("PORT0", strconv.Itoa(port0))
	dr.AddEnv("TASK_HOST", taskHost)
	dr.StdoutFile = context.FilePath("stdout")
	dr.StderrFile = context.FilePath("stderr")
	container, err := dr.Background().Start()
	if err != nil {
		cli.Fatalf("Unable to start container: %s", err)
	}
	cli.AddCleanupTask(func() error {
		return container.KillIfRunning()
	})

	failed := 0
	for _, c := range theContracts {
		cli.Logf(`===> CHECKING CONTRACT: "%s"`, c.Name)
		cli.Logf(`===> Description: %s`, c.Desc(dr))
		if c.Tips != nil {
			cli.Logf("===> **TIPS for this contract:**")
			cli.LogBulletList("     -", c.Tips(dr))
		}
		failed += within(timeout, func() bool {
			return c.Premise(dr)
		})
	}

	if failed != 0 {
		cli.Fatalf("%d contracts failed.", failed)
	}

	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:60,代码来源:_contracts.go


示例4: Stamp

func Stamp(sous *core.Sous, args []string) {
	target := "app"
	if len(args) == 0 {
		cli.Fatalf("sous stamp requires at least one argument (a docker label)")
	}
	_, context := sous.AssembleTargetContext(target)
	if context.BuildNumber() == 0 {
		cli.Fatalf("no builds yet; sous stamp operates on your last successful build of the app target")
	}

	tag := context.DockerTag()
	run := docker.NewRun(tag)
	run.AddLabels(parseLabels(args))
	run.StdoutFile = "/dev/null"
	run.StderrFile = "/dev/null"
	container, err := run.Background().Start()
	if err != nil {
		cli.Fatalf("Failed to start container for labeling: %s", err)
	}
	if err := container.KillIfRunning(); err != nil {
		cli.Fatalf("Failed to kill labelling container %s: %s", container, err)
	}
	cid := container.CID()
	if err := docker.Commit(cid, tag); err != nil {
		cli.Fatalf("Failed to commit labelled container %s: %s", container, err)
	}
	cli.Successf("Successfully added labels to %s; remember to push.", tag)
}
开发者ID:liamjbennett,项目名称:sous,代码行数:28,代码来源:stamp.go


示例5: main

func main() {
	if len(os.Args) < 2 {
		usage()
	}
	sousFlags, args := parseFlags(os.Args[2:])
	command := os.Args[1]
	var cfg *config.Config
	var sous *core.Sous
	if command != "config" {
		updateHourly()
		cfg = config.Load()
		trapSignals()
		defer cli.Cleanup()
		sous = core.NewSous(Version, Revision, OS, Arch, loadCommands(), BuildPacks(cfg), sousFlags, cfg)
	} else {
		sous = core.NewSous(Version, Revision, OS, Arch, loadCommands(), nil, sousFlags, nil)
	}
	c, ok := sous.Commands[command]
	if !ok {
		cli.Fatalf("Command %s not recognised; try `sous help`", command)
	}
	// It is the responsibility of the command to exit with an appropriate
	// error code...
	c.Func(sous, args)
	// If it does not, we assume it failed...
	cli.Fatalf("Command did not complete correctly")
}
开发者ID:liamjbennett,项目名称:sous,代码行数:27,代码来源:main.go


示例6: JSON

func (c *CMD) JSON(v interface{}) {
	o := c.Out()
	if err := json.Unmarshal([]byte(o), &v); err != nil {
		cli.Fatalf("Unable to parse JSON from %s as %T: %s", c, v, err)
	}
	if v == nil {
		cli.Fatalf("Unmarshalled nil")
	}
}
开发者ID:liamjbennett,项目名称:sous,代码行数:9,代码来源:cmd.go


示例7: RequireVersion

func RequireVersion(r *version.R) {
	if c := cmd.ExitCode("git", "--version"); c != 0 {
		cli.Fatalf("git required")
	}
	v := version.Version(cmd.Table("git", "--version")[0][2])
	if !r.IsSatisfiedBy(v) {
		cli.Fatalf("you have git version %s; want %s", v, r.Original)
	}
}
开发者ID:liamjbennett,项目名称:sous,代码行数:9,代码来源:git.go


示例8: Image

func (c *container) Image() string {
	var dc []DockerContainer
	cmd.JSON(&dc, "docker", "inspect", c.Name())
	if len(dc) == 0 {
		cli.Fatalf("Container %s does not exist.", c)
	}
	if len(dc) != 1 {
		cli.Fatalf("Multiple containers match %s", c)
	}
	return dc[0].Image
}
开发者ID:liamjbennett,项目名称:sous,代码行数:11,代码来源:container.go


示例9: ImageID

func ImageID(image string) string {
	var i []Image
	cmd.JSON(&i, "docker", "inspect", image)
	if len(i) == 0 {
		cli.Fatalf("image missing after pull: %s", image)
	}
	if len(i) != 1 {
		cli.Fatalf("multiple images match %s; ensure sous is using unique tags", image)
	}
	return i[0].ID
}
开发者ID:liamjbennett,项目名称:sous,代码行数:11,代码来源:docker.go


示例10: Add

func (ts Targets) Add(target Target) {
	n := target.Name()
	if _, ok := ts[n]; ok {
		cli.Fatalf("target %s already added", n)
	}
	_, ok := knownTargets[n]
	if !ok {
		cli.Fatalf("target %s is not known", n)
	}
	ts[n] = target
}
开发者ID:liamjbennett,项目名称:sous,代码行数:11,代码来源:targets.go


示例11: getLabelsFromImage

func getLabelsFromImage(imageTag string) map[string]string {
	var images []*Image
	cmd.JSON(&images, "docker", "inspect", imageTag)
	if len(images) == 0 {
		cli.Fatalf("cannot find image %s", imageTag)
	}
	if len(images) > 1 {
		cli.Fatalf("multiple images named %s, cannot continue", imageTag)
	}
	image := images[0]
	return image.Config.Labels
}
开发者ID:liamjbennett,项目名称:sous,代码行数:12,代码来源:run.go


示例12: PreDockerBuild

func (t *AppTarget) PreDockerBuild(c *core.Context) {
	if t.artifactPath == "" {
		cli.Fatalf("Artifact path not set by compile target.")
	}
	if !file.Exists(t.artifactPath) {
		cli.Fatalf("Artifact not at %s", t.artifactPath)
	}
	filename := path.Base(t.artifactPath)
	localArtifact := filename
	file.TemporaryLink(t.artifactPath, "./"+localArtifact)
	t.artifactPath = localArtifact
}
开发者ID:liamjbennett,项目名称:sous,代码行数:12,代码来源:app_target.go


示例13: Load

func Load() *Config {
	if c == nil {
		if !file.ReadJSON(&c, "~/.sous/config") {
			if err := Update(); err != nil {
				cli.Fatalf("Unable to load config: %s", err)
			}
			if !file.ReadJSON(&c, "~/.sous/config") {
				cli.Fatalf("Unable to read %s", "~/.sous/config")
			}
		}
	}
	return c
}
开发者ID:liamjbennett,项目名称:sous,代码行数:13,代码来源:config.go


示例14: ReadJSON

func ReadJSON(v interface{}, pathFormat string, a ...interface{}) bool {
	b, exists, path := Read(pathFormat, a...)
	if !exists {
		return false
	}
	if err := json.Unmarshal(b, &v); err != nil {
		cli.Fatalf("Unable to parse JSON in %s as %T: %s", path, v, err)
	}
	if v == nil {
		cli.Fatalf("Unmarshalled nil")
	}
	return true
}
开发者ID:liamjbennett,项目名称:sous,代码行数:13,代码来源:file.go


示例15: SetState

func (t *AppTarget) SetState(fromTarget string, state interface{}) {
	if fromTarget != "compile" {
		return
	}
	m, ok := state.(map[string]string)
	if !ok {
		cli.Fatalf("app target got a %T from compile target, expected map[string]string", state)
	}
	artifactPath, ok := m["artifactPath"]
	if !ok {
		cli.Fatalf("app target got %+v from compile target; expected key 'artifactPath'", m)
	}
	t.artifactPath = artifactPath
}
开发者ID:liamjbennett,项目名称:sous,代码行数:14,代码来源:app_target.go


示例16: Config

func Config(sous *core.Sous, args []string) {
	if len(args) == 0 || len(args) > 2 {
		cli.Fatalf("usage: sous config <key> [<new-value>]")
	}
	if len(args) == 1 {
		if v, ok := config.Properties()[args[0]]; ok {
			cli.Outf(v)
			cli.Success()
		}
		cli.Fatalf("Key %s not found", args[0])
	}
	config.Set(args[0], args[1])
	cli.Logf("Successfully set %s to %s", args[0], args[1])
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:15,代码来源:config.go


示例17: IndexIsDirty

func IndexIsDirty() bool {
	code := cmd.ExitCode("git", "diff-index", "--quiet", "HEAD")
	if code > 1 || code < 0 {
		cli.Fatalf("Unable to determine if git index is dirty; Got exit code %d; want 0-1")
	}
	return code == 1
}
开发者ID:liamjbennett,项目名称:sous,代码行数:7,代码来源:git.go


示例18: getOriginURL

func getOriginURL() *url.URL {
	table := cmd.Table("git", "remote", "-v")
	if len(table) == 0 {
		cli.Fatalf("no git remotes set up")
	}
	for _, row := range table {
		if row[0] == "origin" {
			u, err := url.Parse(row[1])
			if err != nil {
				cli.Fatalf("unable to parse origin (%s) as URL; %s", row[1], err)
			}
			return u
		}
	}
	return nil
}
开发者ID:liamjbennett,项目名称:sous,代码行数:16,代码来源:git.go


示例19: Ls

func Ls(sous *core.Sous, args []string) {
	//globalFlag := lsFlags.Bool("g", false, "global: list files in all projects sous has built")
	//lsFlags.Parse(args)
	//global := *globalFlag
	args = lsFlags.Args()
	if len(args) != 0 {
		cli.Fatalf("sous ls does not accept any arguments")
	}
	_, context := sous.AssembleTargetContext("app")
	cli.Outf(" ===> Images")
	images := sous.LsImages(context)
	if len(images) == 0 {
		cli.Logf("  no images for this project")
	}
	for _, image := range images {
		cli.Logf("  %s:%s", image.Name, image.Tag)
	}
	cli.Outf(" ===> Containers")
	containers := sous.LsContainers(context)
	if len(containers) == 0 {
		cli.Logf("  no containers for this project")
	}
	for _, container := range containers {
		cli.Logf("  %s (%s)", container.Name(), container.CID())
	}
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:27,代码来源:ls.go


示例20: WriteJSON

func WriteJSON(data interface{}, pathFormat string, a ...interface{}) {
	b, err := json.MarshalIndent(data, "", "\t")
	if err != nil {
		cli.Fatalf("Unable to marshal %T object to JSON: %s", data, err)
	}
	Write(b, pathFormat, a...)
}
开发者ID:liamjbennett,项目名称:sous,代码行数:7,代码来源:file.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang swaggering.FormatJSON函数代码示例发布时间:2022-05-28
下一篇:
Golang core.Sous类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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