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


Golang Context.Bool方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: runConnectionBoilerplate

func runConnectionBoilerplate(h *host.Host, c *cli.Context) (string, *auth.AuthOptions, error) {
	hostState, err := h.Driver.GetState()
	if err != nil {
		// TODO: This is a common operation and should have a commonly
		// defined error.
		return "", &auth.AuthOptions{}, fmt.Errorf("Error trying to get host state: %s", err)
	}
	if hostState != state.Running {
		return "", &auth.AuthOptions{}, fmt.Errorf("%s is not running. Please start it in order to use the connection settings.", h.Name)
	}

	dockerHost, err := h.Driver.GetURL()
	if err != nil {
		return "", &auth.AuthOptions{}, fmt.Errorf("Error getting driver URL: %s", err)
	}

	if c.Bool("swarm") {
		var err error
		dockerHost, err = parseSwarm(dockerHost, h)
		if err != nil {
			return "", &auth.AuthOptions{}, fmt.Errorf("Error parsing swarm: %s", err)
		}
	}

	u, err := url.Parse(dockerHost)
	if err != nil {
		return "", &auth.AuthOptions{}, fmt.Errorf("Error parsing URL: %s", err)
	}

	authOptions := h.HostOptions.AuthOptions

	if err := checkCert(u.Host, authOptions, c); err != nil {
		return "", &auth.AuthOptions{}, fmt.Errorf("Error checking and/or regenerating the certs: %s", err)
	}

	return dockerHost, authOptions, nil
}
开发者ID:Red54,项目名称:machine,代码行数:37,代码来源:config.go

示例5: cmdScp

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

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

	store := getStore(c)
	hostInfoLoader := &storeHostInfoLoader{store}

	cmd, err := getScpCmd(src, dest, c.Bool("recursive"), hostInfoLoader)
	if err != nil {
		return err
	}

	if err := runCmdWithStdIo(*cmd); err != nil {
		return err
	}

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

示例6: cmdEnv

func cmdEnv(c *cli.Context) {
	// 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 && !c.Bool("unset") {
		fatal(improperEnvArgsError)
	}

	h := getFirstArgHost(c)

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

	userShell := c.String("shell")
	if userShell == "" {
		shell, err := detectShell()
		if err != nil {
			fatal(err)
		}
		userShell = shell
	}

	t := template.New("envConfig")

	usageHint := generateUsageHint(c.App.Name, c.Args().First(), userShell, c.Bool("no-proxy"), c.Bool("swarm"))

	shellCfg := &ShellConfig{
		DockerCertPath:  authOptions.CertDir,
		DockerHost:      dockerHost,
		DockerTLSVerify: "1",
		UsageHint:       usageHint,
		MachineName:     h.Name,
	}

	if c.Bool("no-proxy") {
		ip, err := h.Driver.GetIP()
		if err != nil {
			fatalf("Error getting host IP: %s", err)
		}

		// first check for an existing lower case no_proxy var
		noProxyVar := "no_proxy"
		noProxyValue := os.Getenv("no_proxy")

		// otherwise default to allcaps HTTP_PROXY
		if noProxyValue == "" {
			noProxyVar = "NO_PROXY"
			noProxyValue = os.Getenv("NO_PROXY")
		}

		// add the docker host to the no_proxy list idempotently
		switch {
		case noProxyValue == "":
			noProxyValue = ip
		case strings.Contains(noProxyValue, ip):
			//ip already in no_proxy list, nothing to do
		default:
			noProxyValue = fmt.Sprintf("%s,%s", noProxyValue, ip)
		}

		shellCfg.NoProxyVar = noProxyVar
		shellCfg.NoProxyValue = noProxyValue
	}

	// unset vars
	if c.Bool("unset") {
		switch userShell {
		case "fish":
			shellCfg.Prefix = "set -e "
			shellCfg.Delimiter = ""
			shellCfg.Suffix = ";\n"
		case "powershell":
			shellCfg.Prefix = "Remove-Item Env:\\\\"
			shellCfg.Delimiter = ""
			shellCfg.Suffix = "\n"
		case "cmd":
			// since there is no way to unset vars in cmd just reset to empty
			shellCfg.DockerCertPath = ""
			shellCfg.DockerHost = ""
			shellCfg.DockerTLSVerify = ""
			shellCfg.Prefix = "set "
			shellCfg.Delimiter = "="
			shellCfg.Suffix = "\n"
		default:
			shellCfg.Prefix = "unset "
			shellCfg.Delimiter = " "
			shellCfg.Suffix = "\n"
		}

		tmpl, err := t.Parse(envTmpl)
		if err != nil {
			fatal(err)
		}

		if err := tmpl.Execute(os.Stdout, shellCfg); err != nil {
			fatal(err)
		}
//.........这里部分代码省略.........
开发者ID:kristiandelay,项目名称:machine,代码行数:101,代码来源:env.go

示例7: cmdCreateInner

func cmdCreateInner(c *cli.Context) {
	if len(c.Args()) > 1 {
		fatalf("Invalid command line. Found extra arguments %v", c.Args()[1:])
	}

	name := c.Args().First()
	driverName := c.String("driver")
	certInfo := getCertPathInfoFromContext(c)

	storePath := c.GlobalString("storage-path")

	store := &persist.Filestore{
		Path:             storePath,
		CaCertPath:       certInfo.CaCertPath,
		CaPrivateKeyPath: certInfo.CaPrivateKeyPath,
	}

	if name == "" {
		cli.ShowCommandHelp(c, "create")
		fatal("Error: No machine name specified.")
	}

	validName := host.ValidateHostName(name)
	if !validName {
		fatal("Error creating machine: ", mcnerror.ErrInvalidHostname)
	}

	if err := validateSwarmDiscovery(c.String("swarm-discovery")); err != nil {
		fatalf("Error parsing swarm discovery: %s", err)
	}

	// TODO: Fix hacky JSON solution
	bareDriverData, err := json.Marshal(&drivers.BaseDriver{
		MachineName: name,
		StorePath:   c.GlobalString("storage-path"),
	})
	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)
	}

	h, err := store.NewHost(driver)
	if err != nil {
		fatalf("Error getting new host: %s", err)
	}

	h.HostOptions = &host.HostOptions{
		AuthOptions: &auth.AuthOptions{
			CertDir:          mcndirs.GetMachineCertDir(),
			CaCertPath:       certInfo.CaCertPath,
			CaPrivateKeyPath: certInfo.CaPrivateKeyPath,
			ClientCertPath:   certInfo.ClientCertPath,
			ClientKeyPath:    certInfo.ClientKeyPath,
			ServerCertPath:   filepath.Join(mcndirs.GetMachineDir(), name, "server.pem"),
			ServerKeyPath:    filepath.Join(mcndirs.GetMachineDir(), name, "server-key.pem"),
			StorePath:        filepath.Join(mcndirs.GetMachineDir(), name),
		},
		EngineOptions: &engine.EngineOptions{
			ArbitraryFlags:   c.StringSlice("engine-opt"),
			Env:              c.StringSlice("engine-env"),
			InsecureRegistry: c.StringSlice("engine-insecure-registry"),
			Labels:           c.StringSlice("engine-label"),
			RegistryMirror:   c.StringSlice("engine-registry-mirror"),
			StorageDriver:    c.String("engine-storage-driver"),
			TlsVerify:        true,
			InstallURL:       c.String("engine-install-url"),
		},
		SwarmOptions: &swarm.SwarmOptions{
			IsSwarm:        c.Bool("swarm"),
			Image:          c.String("swarm-image"),
			Master:         c.Bool("swarm-master"),
			Discovery:      c.String("swarm-discovery"),
			Address:        c.String("swarm-addr"),
			Host:           c.String("swarm-host"),
			Strategy:       c.String("swarm-strategy"),
			ArbitraryFlags: c.StringSlice("swarm-opt"),
		},
	}

	exists, err := store.Exists(h.Name)
	if err != nil {
		fatalf("Error checking if host exists: %s", err)
	}
	if exists {
		fatal(mcnerror.ErrHostAlreadyExists{
			Name: h.Name,
		})
	}

	// driverOpts is the actual data we send over the wire to set the
	// driver parameters (an interface fulfilling drivers.DriverOptions,
	// concrete type rpcdriver.RpcFlags).
	mcnFlags := driver.GetCreateFlags()
	driverOpts := getDriverOpts(c, mcnFlags)

	if err := h.Driver.SetConfigFromFlags(driverOpts); err != nil {
//.........这里部分代码省略.........
开发者ID:Red54,项目名称:machine,代码行数:101,代码来源:create.go

示例8: cmdLs

func cmdLs(c *cli.Context) {
	quiet := c.Bool("quiet")
	filters, err := parseFilters(c.StringSlice("filter"))
	if err != nil {
		fatal(err)
	}

	store := getStore(c)
	hostList, err := listHosts(store)
	if err != nil {
		fatal(err)
	}

	hostList = filterHosts(hostList, filters)

	// Just print out the names if we're being quiet
	if quiet {
		for _, host := range hostList {
			fmt.Println(host.Name)
		}
		return
	}

	swarmMasters := make(map[string]string)
	swarmInfo := make(map[string]string)

	w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
	fmt.Fprintln(w, "NAME\tACTIVE\tDRIVER\tSTATE\tURL\tSWARM")

	for _, host := range hostList {
		swarmOptions := host.HostOptions.SwarmOptions
		if swarmOptions.Master {
			swarmMasters[swarmOptions.Discovery] = host.Name
		}

		if swarmOptions.Discovery != "" {
			swarmInfo[host.Name] = swarmOptions.Discovery
		}
	}

	items := getHostListItems(hostList)

	sortHostListItemsByName(items)

	for _, item := range items {
		activeString := "-"
		if item.Active {
			activeString = "*"
		}

		swarmInfo := ""

		if item.SwarmOptions.Discovery != "" {
			swarmInfo = swarmMasters[item.SwarmOptions.Discovery]
			if item.SwarmOptions.Master {
				swarmInfo = fmt.Sprintf("%s (master)", swarmInfo)
			}
		}
		fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
			item.Name, activeString, item.DriverName, item.State, item.URL, swarmInfo)
	}

	w.Flush()
}
开发者ID:jijojv,项目名称:machine,代码行数:64,代码来源:ls.go


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