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


Golang cli.Context类代码示例

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


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

示例1: cmdConfig

func cmdConfig(c *cli.Context) error {
	// Ensure that log messages always go to stderr when this command is
	// being run (it is intended to be run in a subshell)
	log.SetOutWriter(os.Stderr)

	if len(c.Args()) != 1 {
		return ErrExpectedOneMachine
	}

	host, err := getFirstArgHost(c)
	if err != nil {
		return err
	}

	dockerHost, authOptions, err := runConnectionBoilerplate(host, c)
	if err != nil {
		return fmt.Errorf("Error running connection boilerplate: %s", err)
	}

	log.Debug(dockerHost)

	fmt.Printf("--tlsverify --tlscacert=%q --tlscert=%q --tlskey=%q -H=%s",
		authOptions.CaCertPath, authOptions.ClientCertPath, authOptions.ClientKeyPath, dockerHost)

	return nil
}
开发者ID:rutulpatel,项目名称:machine,代码行数:26,代码来源:config.go

示例2: cmdSsh

func cmdSsh(c *cli.Context) error {
	name := c.Args().First()
	if name == "" {
		return ErrExpectedOneMachine
	}

	store := getStore(c)
	host, err := loadHost(store, name)
	if err != nil {
		return err
	}

	currentState, err := host.Driver.GetState()
	if err != nil {
		return err
	}

	if currentState != state.Running {
		return fmt.Errorf("Error: Cannot run SSH command: Host %q is not running", host.Name)
	}

	client, err := host.CreateSSHClient()
	if err != nil {
		return err
	}

	return client.Shell(c.Args().Tail()...)
}
开发者ID:rutulpatel,项目名称:machine,代码行数:28,代码来源:ssh.go

示例3: cmdSsh

func cmdSsh(c *cli.Context) {
	args := c.Args()
	name := args.First()

	if name == "" {
		fatal("Error: Please specify a machine name.")
	}

	store := getStore(c)
	host, err := loadHost(store, name)
	if err != nil {
		fatal(err)
	}

	currentState, err := host.Driver.GetState()
	if err != nil {
		fatal(err)
	}

	if currentState != state.Running {
		fatalf("Error: Cannot run SSH command: Host %q is not running", host.Name)
	}

	client, err := host.CreateSSHClient()
	if err != nil {
		fatal(err)
	}

	if err := client.Shell(c.Args().Tail()...); err != nil {
		fatal(err)
	}
}
开发者ID:rhendric,项目名称:machine,代码行数:32,代码来源:ssh.go

示例4: cmdScp

func cmdScp(c *cli.Context) error {
	hostLoader = &ScpHostLoader{}

	args := c.Args()
	if len(args) != 2 {
		cli.ShowCommandHelp(c, "scp")
		return errWrongNumberArguments
	}

	// TODO: Check that "-3" flag is available in user's version of scp.
	// It is on every system I've checked, but the manual mentioned it's "newer"
	sshArgs := append(baseSSHArgs, "-3")

	if c.Bool("recursive") {
		sshArgs = append(sshArgs, "-r")
	}

	src := args[0]
	dest := args[1]

	store := getStore(c)

	cmd, err := getScpCmd(src, dest, sshArgs, store)
	if err != nil {
		return err
	}

	return runCmdWithStdIo(*cmd)
}
开发者ID:rutulpatel,项目名称:machine,代码行数:29,代码来源:scp.go

示例5: getStore

func getStore(c *cli.Context) persist.Store {
	certInfo := getCertPathInfoFromContext(c)
	return &persist.Filestore{
		Path:             c.GlobalString("storage-path"),
		CaCertPath:       certInfo.CaCertPath,
		CaPrivateKeyPath: certInfo.CaPrivateKeyPath,
	}
}
开发者ID:KorayAgaya,项目名称:machine,代码行数:8,代码来源:commands.go

示例6: cmdRegenerateCerts

func cmdRegenerateCerts(c *cli.Context) {
	force := c.Bool("force")
	if force || confirmInput("Regenerate TLS machine certs?  Warning: this is irreversible.") {
		log.Infof("Regenerating TLS certificates")
		if err := runActionWithContext("configureAuth", c); err != nil {
			fatal(err)
		}
	}
}
开发者ID:rhendric,项目名称:machine,代码行数:9,代码来源:regeneratecerts.go

示例7: cmdCreateOuter

func cmdCreateOuter(c *cli.Context) {
	driverName := flagHackLookup("--driver")

	// We didn't recognize the driver name.
	if driverName == "" {
		cli.ShowCommandHelp(c, "create")
		return
	}

	name := c.Args().First()

	// TODO: Fix hacky JSON solution
	bareDriverData, err := json.Marshal(&drivers.BaseDriver{
		MachineName: name,
	})
	if err != nil {
		fatalf("Error attempting to marshal bare driver data: %s", err)
	}

	driver, err := newPluginDriver(driverName, bareDriverData)
	if err != nil {
		fatalf("Error loading driver %q: %s", driverName, err)
	}

	// TODO: So much flag manipulation and voodoo here, it seems to be
	// asking for trouble.
	//
	// mcnFlags is the data we get back over the wire (type mcnflag.Flag)
	// to indicate which parameters are available.
	mcnFlags := driver.GetCreateFlags()

	// This bit will actually make "create" display the correct flags based
	// on the requested driver.
	cliFlags, err := convertMcnFlagsToCliFlags(mcnFlags)
	if err != nil {
		fatalf("Error trying to convert provided driver flags to cli flags: %s", err)
	}
	for i := range c.App.Commands {
		cmd := &c.App.Commands[i]
		if cmd.HasName("create") {
			cmd = addDriverFlagsToCommand(cliFlags, cmd)
		}
	}

	if err := driver.Close(); err != nil {
		fatal(err)
	}

	if err := c.App.Run(os.Args); err != nil {
		fatal(err)
	}
}
开发者ID:rhendric,项目名称:machine,代码行数:52,代码来源:create.go

示例8: cmdStatus

func cmdStatus(c *cli.Context) {
	if len(c.Args()) != 1 {
		fatal(ErrExpectedOneMachine)
	}

	host := getFirstArgHost(c)
	currentState, err := host.Driver.GetState()
	if err != nil {
		log.Errorf("error getting state for host %s: %s", host.Name, err)
	}

	log.Info(currentState)
}
开发者ID:rhendric,项目名称:machine,代码行数:13,代码来源:status.go

示例9: getHostsFromContext

func getHostsFromContext(c *cli.Context) ([]*host.Host, error) {
	store := getStore(c)
	hosts := []*host.Host{}

	for _, hostName := range c.Args() {
		h, err := loadHost(store, hostName)
		if err != nil {
			return nil, fmt.Errorf("Could not load host %q: %s", hostName, err)
		}
		hosts = append(hosts, h)
	}

	return hosts, nil
}
开发者ID:KorayAgaya,项目名称:machine,代码行数:14,代码来源:commands.go

示例10: getCertPathInfoFromContext

// Returns the cert paths.
// codegangsta/cli will not set the cert paths if the storage-path is set to
// something different so we cannot use the paths in the global options. le
// sigh.
func getCertPathInfoFromContext(c *cli.Context) cert.CertPathInfo {
	caCertPath := c.GlobalString("tls-ca-cert")
	caKeyPath := c.GlobalString("tls-ca-key")
	clientCertPath := c.GlobalString("tls-client-cert")
	clientKeyPath := c.GlobalString("tls-client-key")

	if caCertPath == "" {
		caCertPath = filepath.Join(mcndirs.GetMachineCertDir(), "ca.pem")
	}

	if caKeyPath == "" {
		caKeyPath = filepath.Join(mcndirs.GetMachineCertDir(), "ca-key.pem")
	}

	if clientCertPath == "" {
		clientCertPath = filepath.Join(mcndirs.GetMachineCertDir(), "cert.pem")
	}

	if clientKeyPath == "" {
		clientKeyPath = filepath.Join(mcndirs.GetMachineCertDir(), "key.pem")
	}

	return cert.CertPathInfo{
		CaCertPath:       caCertPath,
		CaPrivateKeyPath: caKeyPath,
		ClientCertPath:   clientCertPath,
		ClientKeyPath:    clientKeyPath,
	}
}
开发者ID:KorayAgaya,项目名称:machine,代码行数:33,代码来源:commands.go

示例11: cmdActive

func cmdActive(c *cli.Context) {
	if len(c.Args()) > 0 {
		fatal("Error: Too many arguments given.")
	}

	store := getStore(c)
	host, err := getActiveHost(store)
	if err != nil {
		fatalf("Error getting active host: %s", err)
	}

	if host != nil {
		fmt.Println(host.Name)
	}
}
开发者ID:jijojv,项目名称:machine,代码行数:15,代码来源:active.go

示例12: cmdConfig

func cmdConfig(c *cli.Context) {
	if len(c.Args()) != 1 {
		fatal(ErrExpectedOneMachine)
	}

	h := getFirstArgHost(c)

	dockerHost, authOptions, err := runConnectionBoilerplate(h, c)
	if err != nil {
		fatalf("Error running connection boilerplate: %s", err)
	}

	log.Debug(dockerHost)

	fmt.Printf("--tlsverify --tlscacert=%q --tlscert=%q --tlskey=%q -H=%s",
		authOptions.CaCertPath, authOptions.ClientCertPath, authOptions.ClientKeyPath, dockerHost)
}
开发者ID:Red54,项目名称:machine,代码行数:17,代码来源:config.go

示例13: cmdInspect

func cmdInspect(c *cli.Context) error {
	if len(c.Args()) == 0 {
		cli.ShowCommandHelp(c, "inspect")
		return ErrExpectedOneMachine
	}

	host, err := getFirstArgHost(c)
	if err != nil {
		return err
	}

	tmplString := c.String("format")
	if tmplString != "" {
		var tmpl *template.Template
		var err error
		if tmpl, err = template.New("").Funcs(funcMap).Parse(tmplString); err != nil {
			return fmt.Errorf("Template parsing error: %v\n", err)
		}

		jsonHost, err := json.Marshal(host)
		if err != nil {
			return err
		}

		obj := make(map[string]interface{})
		if err := json.Unmarshal(jsonHost, &obj); err != nil {
			return err
		}

		if err := tmpl.Execute(os.Stdout, obj); err != nil {
			return err
		}

		os.Stdout.Write([]byte{'\n'})
	} else {
		prettyJSON, err := json.MarshalIndent(host, "", "    ")
		if err != nil {
			return err
		}

		fmt.Println(string(prettyJSON))
	}

	return nil
}
开发者ID:rutulpatel,项目名称:machine,代码行数:45,代码来源:inspect.go

示例14: cmdActive

func cmdActive(c *cli.Context) error {
	if len(c.Args()) > 0 {
		return errTooManyArguments
	}

	store := getStore(c)

	host, err := getActiveHost(store)
	if err != nil {
		return fmt.Errorf("Error getting active host: %s", err)
	}

	if host != nil {
		fmt.Println(host.Name)
	}

	return nil
}
开发者ID:rutulpatel,项目名称:machine,代码行数:18,代码来源:active.go

示例15: cmdRm

func cmdRm(c *cli.Context) {
	if len(c.Args()) == 0 {
		cli.ShowCommandHelp(c, "rm")
		fatal("You must specify a machine name")
	}

	force := c.Bool("force")
	store := getStore(c)

	for _, hostName := range c.Args() {
		h, err := loadHost(store, hostName)
		if err != nil {
			fatalf("Error removing host %q: %s", hostName, err)
		}
		if err := h.Driver.Remove(); err != nil {
			if !force {
				log.Errorf("Provider error removing machine %q: %s", hostName, err)
				continue
			}
		}

		if err := store.Remove(hostName); err != nil {
			log.Errorf("Error removing machine %q from store: %s", hostName, err)
		} else {
			log.Infof("Successfully removed %s", hostName)
		}
	}
}
开发者ID:rhendric,项目名称:machine,代码行数:28,代码来源:rm.go


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