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


Golang cli.Fatalf函数代码示例

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


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


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