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


Golang cmd.Fail函数代码示例

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


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

示例1: setEnvironment

func (ctx *CommandContext) setEnvironment(c *cobra.Command, args []string) {
	if err := ctx.environment.ExtractVariablesFrom(&args, false); err != nil {
		cmd.Fail(1, err.Error())
	}

	if len(args) < 1 {
		cmd.Fail(1, "Valid arguments: <name>... <key>=<value>...")
	}

	t := ctx.Transport.Get()

	ids, err := cloc.NewContainerLocators(t, args...)
	if err != nil {
		cmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			ctx.environment.Description.Id = cloc.AsIdentifier(on)
			if ctx.resetEnv {
				return &cjobs.PutEnvironmentRequest{ctx.environment.Description}
			}

			return &cjobs.PatchEnvironmentRequest{ctx.environment.Description}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:30,代码来源:cmd.go

示例2: buildImage

func (ctx *CommandContext) buildImage(c *cobra.Command, args []string) {
	if err := ctx.environment.ExtractVariablesFrom(&args, false); err != nil {
		cmd.Fail(1, err.Error())
	}

	if len(args) < 3 {
		cmd.Fail(1, "Valid arguments: <source> <image> <tag> ...")
	}

	buildReq := &ctx.buildReq

	if buildReq.CallbackUrl != "" {
		_, err := url.ParseRequestURI(buildReq.CallbackUrl)
		if err != nil {
			cmd.Fail(1, "The callbackUrl was an invalid URL")
		}
	}

	buildReq.Source = args[0]
	buildReq.BaseImage = args[1]
	buildReq.Tag = args[2]
	buildReq.Writer = os.Stdout
	buildReq.DockerSocket = ctx.dockerSocket
	buildReq.Environment = ctx.environment.Description.Map()

	res, err := sti.Build(buildReq)
	if err != nil {
		fmt.Printf("An error occured: %s\n", err.Error())
		return
	}

	for _, message := range res.Messages {
		fmt.Println(message)
	}
}
开发者ID:pmorie,项目名称:geard,代码行数:35,代码来源:cmd.go

示例3: deleteContainer

func (ctx *CommandContext) deleteContainer(c *cobra.Command, args []string) {
	t := ctx.Transport.Get()

	if err := ExtractContainerLocatorsFromDeployment(t, ctx.deploymentPath, &args); err != nil {
		cmd.Fail(1, err.Error())
	}

	if len(args) < 1 {
		cmd.Fail(1, "Valid arguments: <id> ...")
	}

	ids, err := cloc.NewContainerLocators(t, args...)
	if err != nil {
		cmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			return &cjobs.DeleteContainerRequest{
				Id: cloc.AsIdentifier(on),
			}
		},
		Output: os.Stdout,
		OnSuccess: func(r *cmd.CliJobResponse, w io.Writer, job cmd.RequestedJob) {
			fmt.Fprintf(w, "Deleted %s", string(job.Request.(*cjobs.DeleteContainerRequest).Id))
		},
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:30,代码来源:cmd.go

示例4: stopContainer

func stopContainer(cmd *cobra.Command, args []string) {
	t := defaultTransport.Get()

	if err := gcmd.ExtractContainerLocatorsFromDeployment(t, deploymentPath, &args); err != nil {
		gcmd.Fail(1, err.Error())
	}
	if len(args) < 1 {
		gcmd.Fail(1, "Valid arguments: <id> ...")
	}
	ids, err := gcmd.NewContainerLocators(t, args...)
	if err != nil {
		gcmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	gcmd.Executor{
		On: ids,
		Serial: func(on gcmd.Locator) gcmd.JobRequest {
			return &cjobs.StoppedContainerStateRequest{
				Id: gcmd.AsIdentifier(on),
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
开发者ID:jhadvig,项目名称:geard,代码行数:25,代码来源:commands.go

示例5: linkContainers

func (ctx *CommandContext) linkContainers(c *cobra.Command, args []string) {
	if len(args) < 1 {
		cmd.Fail(1, "Valid arguments: <id> ...")
	}

	t := ctx.Transport.Get()

	ids, err := cloc.NewContainerLocators(t, args...)
	if err != nil {
		cmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}
	if ctx.networkLinks.NetworkLinks == nil {
		ctx.networkLinks.NetworkLinks = &containers.NetworkLinks{}
	}

	cmd.Executor{
		On: ids,
		Group: func(on ...cmd.Locator) cmd.JobRequest {
			links := &containers.ContainerLinks{make([]containers.ContainerLink, 0, len(on))}
			for i := range on {
				links.Links = append(links.Links, containers.ContainerLink{cloc.AsIdentifier(on[i]), *ctx.networkLinks.NetworkLinks})
			}
			return &cjobs.LinkContainersRequest{links}
		},
		Output: os.Stdout,
		OnSuccess: func(r *cmd.CliJobResponse, w io.Writer, job cmd.RequestedJob) {
			fmt.Fprintf(w, "Links set on %s\n", job.Request.(*cjobs.LinkContainersRequest).ContainerLinks.String())
		},
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:31,代码来源:cmd.go

示例6: restartContainer

func (ctx *CommandContext) restartContainer(c *cobra.Command, args []string) {
	t := ctx.Transport.Get()

	if err := ExtractContainerLocatorsFromDeployment(t, ctx.deploymentPath, &args); err != nil {
		cmd.Fail(1, err.Error())
	}
	if len(args) < 1 {
		cmd.Fail(1, "Valid arguments: <id> ...")
	}
	ids, err := cloc.NewContainerLocators(t, args...)
	if err != nil {
		cmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			return &cjobs.RestartContainerRequest{
				Id: cloc.AsIdentifier(on),
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:25,代码来源:cmd.go

示例7: startIdler

func startIdler(c *cobra.Command, args []string) {
	systemd.Require()
	dockerSocket := c.Flags().Lookup("docker-socket").Value.String()

	dockerClient, err := docker.GetConnection(dockerSocket)
	if err != nil {
		cmd.Fail(1, "Unable to connect to docker on URI %s", dockerSocket)
	}

	if err := idler.StartIdler(dockerClient, hostIp, idleTimeout); err != nil {
		cmd.Fail(2, err.Error())
	}
}
开发者ID:roacobb,项目名称:geard,代码行数:13,代码来源:cmd.go

示例8: installImage

func (ctx *CommandContext) installImage(c *cobra.Command, args []string) {
	if err := ctx.environment.ExtractVariablesFrom(&args, true); err != nil {
		cmd.Fail(1, err.Error())
	}

	if len(args) < 2 {
		cmd.Fail(1, "Valid arguments: <image_name> <id> ...")
	}

	t := ctx.Transport.Get()

	imageId := args[0]
	if imageId == "" {
		cmd.Fail(1, "Argument 1 must be a Docker image to base the service on")
	}
	ids, err := cloc.NewContainerLocators(t, args[1:]...)
	if err != nil {
		cmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	for _, locator := range ids {
		if imageId == string(cloc.AsIdentifier(locator)) {
			cmd.Fail(1, "Image name and container id must not be the same: %s", imageId)
		}
	}

	cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			r := cjobs.InstallContainerRequest{
				RequestIdentifier: jobs.NewRequestIdentifier(),

				Id:               cloc.AsIdentifier(on),
				Image:            imageId,
				Started:          ctx.start,
				Isolate:          ctx.isolate,
				SocketActivation: ctx.sockAct,

				Ports:        *ctx.portPairs.Get().(*port.PortPairs),
				Environment:  &ctx.environment.Description,
				NetworkLinks: ctx.networkLinks.NetworkLinks,
				VolumeConfig: ctx.volumeConfig.VolumeConfig,
				SystemdSlice: ctx.systemdSlice,
			}
			return &r
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
开发者ID:jcantrill,项目名称:geard,代码行数:50,代码来源:cmd.go

示例9: keysForUser

func keysForUser(c *cobra.Command, args []string) {
	if len(args) != 1 {
		cmd.Fail(1, "Valid arguments: <login name>\n")
	}

	u, err := user.Lookup(args[0])
	if err != nil {
		cmd.Fail(2, "Unable to lookup user")
	}

	if err := ssh.GenerateAuthorizedKeysFor(u, false, false); err != nil {
		cmd.Fail(1, "Unable to generate authorized_keys file: %s", err.Error())
	}
}
开发者ID:jcantrill,项目名称:geard,代码行数:14,代码来源:cmd.go

示例10: main

func main() {
	gearCmd := &cobra.Command{
		Use:   "gear",
		Short: "Gear(d) is a tool for installing Docker containers to systemd",
		Long:  "A commandline client and server that installs Docker containers to systemd.\n\nComplete documentation is available at http://github.com/openshift/geard",
		Run: func(c *cobra.Command, args []string) {
			c.Help()
		},
	}
	gearCmd.PersistentFlags().Var(&defaultTransport, "transport", "Specify an alternate mechanism to connect to the gear agent")
	gearCmd.PersistentFlags().BoolVar(&(config.SystemDockerFeatures.EnvironmentFile), "has-env-file", true, "Use --env-file with Docker, set false if older than 0.11")
	gearCmd.PersistentFlags().BoolVar(&(config.SystemDockerFeatures.ForegroundRun), "has-foreground", false, "(experimental) Use --foreground with Docker, requires alexlarsson/forking-run")
	gearCmd.PersistentFlags().BoolVarP(&insecure, "insecure", "k", false, "Do not verify CA certificate on SSL connections and transfers")

	// declare remote, then local commands
	cmd.ExtendCommands(gearCmd, false)
	cmd.ExtendCommands(gearCmd, true)

	// version information
	versionCmd := &cobra.Command{
		Use:   "version",
		Short: "Display version",
		//Long:  "Display version",
		Run: func(c *cobra.Command, args []string) {
			fmt.Printf("gear %s\n", version)
		},
	}
	gearCmd.AddCommand(versionCmd)

	// run
	if err := gearCmd.Execute(); err != nil {
		cmd.Fail(1, err.Error())
	}
}
开发者ID:kshi0310,项目名称:geard,代码行数:34,代码来源:main.go

示例11: buildImage

func buildImage(cmd *cobra.Command, args []string) {
	if err := environment.ExtractVariablesFrom(&args, false); err != nil {
		gcmd.Fail(1, err.Error())
	}

	if len(args) < 3 {
		gcmd.Fail(1, "Valid arguments: <source> <build image> <tag> ...")
	}

	if buildReq.CallbackUrl != "" {
		_, err := url.ParseRequestURI(buildReq.CallbackUrl)
		if err != nil {
			gcmd.Fail(1, "The callbackUrl was an invalid URL")
		}
	}

	buildReq.Source = args[0]
	buildReq.BaseImage = args[1]
	buildReq.Tag = args[2]
	buildReq.Writer = os.Stdout
	buildReq.DockerSocket = conf.Docker.Socket
	buildReq.Environment = environment.Description.Map()

	if buildReq.WorkingDir == "tempdir" {
		var err error
		buildReq.WorkingDir, err = ioutil.TempDir("", "sti")
		if err != nil {
			fmt.Println(err.Error())
			return
		}
		defer os.Remove(buildReq.WorkingDir)
	}

	res, err := sti.Build(buildReq)
	if err != nil {
		fmt.Printf("An error occured: %s\n", err.Error())
		return
	}

	for _, message := range res.Messages {
		fmt.Println(message)
	}
}
开发者ID:jhadvig,项目名称:geard,代码行数:43,代码来源:commands.go

示例12: initRepository

func initRepository(c *cobra.Command, args []string) {
	if len(args) < 1 || len(args) > 2 {
		cmd.Fail(1, "Valid arguments: <repo_id> [<repo_url>]\n")
	}

	repoId, err := containers.NewIdentifier(args[0])
	if err != nil {
		cmd.Fail(1, "Argument 1 must be a valid repository identifier: %s\n", err.Error())
	}

	repoUrl := ""
	if len(args) == 2 {
		repoUrl = args[1]
	}

	if err := gjobs.InitializeRepository(git.RepoIdentifier(repoId), repoUrl); err != nil {
		cmd.Fail(2, "Unable to initialize repository %s\n", err.Error())
	}
}
开发者ID:jcantrill,项目名称:geard,代码行数:19,代码来源:init_repo_linux.go

示例13: createToken

func (ctx *CommandContext) createToken(c *cobra.Command, args []string) {
	if len(args) != 1 {
		cmd.Fail(1, "Valid arguments: <content>")
	}

	if ctx.keyPath == "" {
		cmd.Fail(1, "You must specify --key-path to create a token")
	}
	config, err := encrypted.NewTokenConfiguration(filepath.Join(ctx.keyPath, "client"), filepath.Join(ctx.keyPath, "server.pub"))
	if err != nil {
		cmd.Fail(1, "Unable to load token configuration: %s", err.Error())
	}

	value, err := config.Sign(args[0], "key", ctx.expiresAt)
	if err != nil {
		cmd.Fail(1, "Unable to sign this request: %s", err.Error())
	}
	fmt.Printf("%s", value)
	os.Exit(0)
}
开发者ID:pmorie,项目名称:geard,代码行数:20,代码来源:cmd.go

示例14: containerStatus

func (ctx *CommandContext) containerStatus(c *cobra.Command, args []string) {
	t := ctx.Transport.Get()

	if err := ExtractContainerLocatorsFromDeployment(t, ctx.deploymentPath, &args); err != nil {
		cmd.Fail(1, err.Error())
	}
	if len(args) < 1 {
		cmd.Fail(1, "Valid arguments: <id> ...")
	}
	ids, err := cloc.NewContainerLocators(t, args...)
	if err != nil {
		cmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	data, errors := cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			return &cjobs.ContainerStatusRequest{
				Id: cloc.AsIdentifier(on),
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.Gather()

	for i := range data {
		if buf, ok := data[i].(*bytes.Buffer); ok {
			if i > 0 {
				fmt.Fprintf(os.Stdout, "\n-------------\n")
			}
			buf.WriteTo(os.Stdout)
		}
	}
	if len(errors) > 0 {
		for i := range errors {
			fmt.Fprintf(os.Stderr, "Error: %s\n", errors[i])
		}
		os.Exit(1)
	}
	os.Exit(0)
}
开发者ID:pmorie,项目名称:geard,代码行数:41,代码来源:cmd.go

示例15: transportAndHosts

func (ctx *CommandContext) transportAndHosts(args ...string) (transport.Transport, cmd.Locators) {
	t := ctx.Transport.Get()

	if len(args) == 0 {
		args = []string{transport.Local.String()}
	}
	servers, err := cmd.NewHostLocators(t, args[0:]...)
	if err != nil {
		cmd.Fail(1, "You must pass zero or more valid host names (use '%s' or pass no arguments for the current server): %s", transport.Local.String(), err.Error())
	}

	return t, servers
}
开发者ID:pmorie,项目名称:geard,代码行数:13,代码来源:cmd.go


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