當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cli.Context類代碼示例

本文整理匯總了Golang中github.com/cloud66/cli.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: runSettings

func runSettings(c *cli.Context) {
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()
	var settings []cloud66.StackSetting
	var err error
	stack := mustStack(c)
	settings, err = client.StackSettings(stack.Uid)
	must(err)

	settingNames := c.Args()
	sort.Strings(settingNames)
	if len(settingNames) == 0 {
		printSettingList(w, settings)
	} else {
		// filter out the unwanted settings
		var filteredSettings []cloud66.StackSetting
		for _, i := range settings {
			sorted := sort.SearchStrings(settingNames, i.Key)
			if sorted < len(settingNames) && settingNames[sorted] == i.Key {
				filteredSettings = append(filteredSettings, i)
			}
		}

		printSettingList(w, filteredSettings)
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:26,代碼來源:settings.go

示例2: runUploadManifestYaml

func runUploadManifestYaml(c *cli.Context, stackUid string) {
	manifestYamlFile := c.Args().First()
	if manifestYamlFile == "" {
		printFatal("manifest_yaml file path is required")
	} else {
		manifestYamlFile = expandPath(manifestYamlFile)
	}
	manifestYamlBytes, err := ioutil.ReadFile(manifestYamlFile)
	must(err)
	manifestYaml := string(manifestYamlBytes)

	comments := c.String("comments")
	if comments == "" {
		fmt.Println("\nComments can't be blank, Please add one:")
		if term.IsTerminal(os.Stdin) {
			fmt.Printf("> ")
		}

		reader := bufio.NewReader(os.Stdin)
		if comments, err = reader.ReadString('\n'); err != nil {
			printFatal(err.Error())
		}
	}

	_, err = client.CreateManifestYaml(stackUid, manifestYaml, comments)
	must(err)
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:27,代碼來源:stack-configure.go

示例3: runEasyDeploy

func runEasyDeploy(c *cli.Context) {
	appNames := c.Args()

	if len(appNames) != 0 {
		w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
		defer w.Flush()

		var items []cloud66.EasyDeploy
		for _, appName := range appNames {
			item, err := client.EasyDeployInfo(appName)
			if err != nil {
				printFatal(err.Error())
				return
			}

			items = append(items, *item)
		}

		printEasyDeployList(w, items)

	} else {
		list, err := client.EasyDeployList()
		if err != nil {
			printFatal("Error during fetching the list: " + err.Error())
			return
		}

		for _, easyDeploy := range list {
			fmt.Println(easyDeploy)
		}
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:32,代碼來源:easy-deploy.go

示例4: runContainerStop

func runContainerStop(c *cli.Context) {
	if len(c.Args()) == 0 {
		cli.ShowSubcommandHelp(c)
		os.Exit(2)
	}

	stack := mustStack(c)
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()

	containerUid := c.Args()[0]
	container, err := client.GetContainer(stack.Uid, containerUid)
	must(err)

	if container == nil {
		printFatal("Container with Id '" + containerUid + "' not found")
	}

	asyncId, err := startContainerStop(stack.Uid, containerUid)
	if err != nil {
		printFatal(err.Error())
	}
	genericRes, err := endServerSet(*asyncId, stack.Uid)
	if err != nil {
		printFatal(err.Error())
	}
	printGenericResponse(*genericRes)
	return
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:29,代碼來源:container-stop.go

示例5: runServerSettings

func runServerSettings(c *cli.Context) {
	stack := mustStack(c)

	// get the server
	serverName := c.String("server")
	if len(serverName) == 0 {
		cli.ShowSubcommandHelp(c)
		os.Exit(2)
	}

	servers, err := client.Servers(stack.Uid)
	if err != nil {
		printFatal(err.Error())
	}

	server, err := findServer(servers, serverName)
	if err != nil {
		printFatal(err.Error())
	}

	if server == nil {
		printFatal("Server '" + serverName + "' not found")
	}

	fmt.Printf("Server: %s\n", server.Name)

	getServerSettings(*stack, *server, c.Args())
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:28,代碼來源:servers-settings-list.go

示例6: runEnvVars

func runEnvVars(c *cli.Context) {
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()
	var envVars []cloud66.StackEnvVar
	var err error
	stack := mustStack(c)
	envVars, err = client.StackEnvVars(stack.Uid)
	must(err)

	envVarKeys := c.Args()
	flagShowHistory := c.Bool("history")

	sort.Strings(envVarKeys)
	if len(envVarKeys) == 0 {
		printEnvVarsList(w, envVars, flagShowHistory)
	} else {
		// filter out the unwanted env_vars
		var filteredEnvVars []cloud66.StackEnvVar
		for _, i := range envVars {
			sorted := sort.SearchStrings(envVarKeys, i.Key)
			if sorted < len(envVarKeys) && envVarKeys[sorted] == i.Key {
				filteredEnvVars = append(filteredEnvVars, i)
			}
		}
		printEnvVarsList(w, filteredEnvVars, flagShowHistory)
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:27,代碼來源:env-vars.go

示例7: runContainerAttach

func runContainerAttach(c *cli.Context) {
	if len(c.Args()) != 1 {
		cli.ShowSubcommandHelp(c)
		os.Exit(2)
	}

	fmt.Println("Attaching to container...")

	stack := mustStack(c)
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()

	containerUid := c.Args()[0]
	container, err := client.GetContainer(stack.Uid, containerUid)
	must(err)

	if container == nil {
		printFatal("Container with Id '" + containerUid + "' not found")
	}

	server, err := client.GetServer(stack.Uid, container.ServerUid, 0)
	must(err)

	userCommand := fmt.Sprintf("sudo docker attach --no-stdin=true --sig-proxy=false %s", container.Uid)

	err = SshToServerForCommand(*server, userCommand, false)
	if err != nil {
		printFatal(err.Error())
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:30,代碼來源:container-attach.go

示例8: runBackups

func runBackups(c *cli.Context) {
	var dbType = c.String("dbtype")

	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()

	stack := mustStack(c)

	backups, err := client.ManagedBackups(stack.Uid)
	must(err)

	var dbTypeGroup = map[string][]cloud66.ManagedBackup{}
	if c.Bool("latest") {
		for _, i := range backups {
			if dbTypeGroup[i.DbType] == nil {
				// it's a new one
				dbTypeGroup[i.DbType] = []cloud66.ManagedBackup{i}
			} else {
				dbTypeGroup[i.DbType] = append(dbTypeGroup[i.DbType], i)
			}
		}

		// now sort each group
		topResults := []cloud66.ManagedBackup{}
		for _, v := range dbTypeGroup {
			sort.Sort(backupsByDate(v))
			topResults = append(topResults, v[0])
		}
		printBackupList(w, topResults, dbType)
	} else {
		printBackupList(w, backups, dbType)
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:33,代碼來源:backups.go

示例9: runServers

func runServers(c *cli.Context) {
	stack := mustStack(c)
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()

	var servers []cloud66.Server
	var err error
	servers, err = client.Servers(stack.Uid)
	must(err)

	serverNames := c.Args()

	for idx, i := range serverNames {
		serverNames[idx] = strings.ToLower(i)
	}
	sort.Strings(serverNames)
	if len(serverNames) == 0 {
		printServerList(w, servers)
	} else {
		// filter out the unwanted servers
		var filteredServers []cloud66.Server
		for _, i := range servers {
			sorted := sort.SearchStrings(serverNames, strings.ToLower(i.Name))
			if sorted < len(serverNames) && strings.ToLower(serverNames[sorted]) == strings.ToLower(i.Name) {
				filteredServers = append(filteredServers, i)
			}
		}
		printServerList(w, filteredServers)
	}
}
開發者ID:magiccreater,項目名稱:cx,代碼行數:30,代碼來源:servers.go

示例10: initClients

func initClients(c *cli.Context) {
	// is there a token file?
	_, err := os.Stat(filepath.Join(cxHome(), tokenFile))
	if err != nil {
		fmt.Println("No previous authentication found.")
		cloud66.Authorize(cxHome(), tokenFile)
		os.Exit(1)
	} else {
		client = cloud66.GetClient(cxHome(), tokenFile, VERSION)
		debugMode = c.GlobalBool("debug")
		client.Debug = debugMode
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:13,代碼來源:main.go

示例11: runUpload

func runUpload(c *cli.Context) {
	if runtime.GOOS == "windows" {
		printFatal("Not supported on Windows")
		os.Exit(2)
	}

	stack := mustStack(c)

	// args start after stack name
	// and check if user specified target directory
	var targetDirectory string = ""

	if len(c.Args()) < 1 {
		cli.ShowCommandHelp(c, "upload")
		os.Exit(2)
	} else if len(c.Args()) == 2 {
		targetDirectory = c.Args()[1]
	}

	// get the server
	serverName := c.String("server")
	// get the file path
	filePath := c.Args()[0]

	servers, err := client.Servers(stack.Uid)
	if err != nil {
		printFatal(err.Error())
	}

	server, err := findServer(servers, serverName)
	if err != nil {
		printError("server not found, please ensure correct server is specified in command.")
		os.Exit(2)
	}

	if server == nil {
		printFatal("Server '" + serverName + "' not found")
	}

	fmt.Printf("Server: %s\n", server.Name)

	if targetDirectory == "" {
		err = sshToServerToUpload(*server, filePath)
	} else {
		err = sshToServerToUpload(*server, filePath, targetDirectory)
	}

	if err != nil {
		printFatal(err.Error())
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:51,代碼來源:upload.go

示例12: runJobs

func runJobs(c *cli.Context) {
	flagServer := c.String("server")
	flagServiceName := c.String("service")
	stack := mustStack(c)
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()

	var serverUid *string
	if flagServer == "" {
		serverUid = nil
	} else {
		servers, err := client.Servers(stack.Uid)
		if err != nil {
			printFatal(err.Error())
		}
		server, err := findServer(servers, flagServer)
		if err != nil {
			printFatal(err.Error())
		}
		if server == nil {
			printFatal("Server '" + flagServer + "' not found")
		}
		if !server.HasRole("docker") {
			printFatal("Server '" + flagServer + "' can not host containers")
		}
		fmt.Printf("Server: %s\n", server.Name)
		serverUid = &server.Uid
	}

	var (
		jobs []cloud66.Job
		err  error
	)

	if flagServiceName == "" {
		jobs, err = client.GetJobs(stack.Uid, serverUid)
		must(err)
	}
	// else {
	// 	service, err := client.GetService(stack.Uid, flagServiceName, serverUid, nil)
	// 	must(err)
	// 	if service == nil {
	// 		printFatal("Service '" + flagServiceName + "' not found on specified stack")
	// 	} else {
	// 		services = make([]cloud66.Service, 1)
	// 		services[0] = *service
	// 	}
	// }
	printJobsList(w, jobs, flagServer)
}
開發者ID:magiccreater,項目名稱:cx,代碼行數:50,代碼來源:jobs.go

示例13: runContainerExec

func runContainerExec(c *cli.Context) {
	if len(c.Args()) != 2 {
		cli.ShowSubcommandHelp(c)
		os.Exit(2)
	}

	fmt.Println("Running exec on container...")

	stack := mustStack(c)
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()

	containerUid := c.Args()[0]
	command := c.Args()[1]
	container, err := client.GetContainer(stack.Uid, containerUid)
	must(err)

	if container == nil {
		printFatal("Container with Id '" + containerUid + "' not found")
	}

	server, err := client.GetServer(stack.Uid, container.ServerUid, 0)
	must(err)

	dockerFlags := c.String("docker-flags")
	userCommand := fmt.Sprintf("sudo docker exec %s %s %s", dockerFlags, container.Uid, command)
	err = SshToServerForCommand(*server, userCommand, true)
	if err != nil {
		printFatal(err.Error())
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:31,代碼來源:container-exec.go

示例14: runUpdate

func runUpdate(c *cli.Context) {
	debugMode = c.GlobalBool("debug")
	flagForcedVersion = c.String("force")

	if debugMode {
		fmt.Printf("Current version is %s\n", VERSION)
		if flagForcedVersion == "" {
			fmt.Println("No forced version")
		} else {
			fmt.Printf("Forced version is %s\n", flagForcedVersion)
		}
	}
	updateIt, err := needUpdate()
	if err != nil {
		if debugMode {
			fmt.Printf("Cannot verify need for update %v\n", err)
		}
		return
	}
	if !updateIt {
		if debugMode {
			fmt.Println("No need for update")
		}
		return
	}

	// houston we have an update. which one do we need?
	download, err := getVersionManifest(flagForcedVersion)
	if err != nil {
		if debugMode {
			fmt.Printf("Error fetching manifest %v\n", err)
		}
	}
	if download == nil {
		if debugMode {
			fmt.Println("Found no matching download for the current OS and ARCH")
		}
		return
	}

	err = download.update()
	if err != nil {
		if debugMode {
			fmt.Printf("Failed to update: %v\n", err)
		}
		return
	}
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:48,代碼來源:update.go

示例15: runEnvVarsSet

func runEnvVarsSet(c *cli.Context) {
	if len(c.Args()) != 1 {
		cli.ShowSubcommandHelp(c)
		os.Exit(2)
	}

	kv := c.Args()[0]
	kvs := strings.Split(kv, "=")

	if len(kvs) != 2 {
		cli.ShowSubcommandHelp(c)
		os.Exit(2)
	}

	key := strings.ToUpper(kvs[0])
	value := kvs[1]

	stack := mustStack(c)

	envVars, err := client.StackEnvVars(stack.Uid)
	must(err)

	existing := false
	for _, i := range envVars {
		if i.Key == key {
			if i.Readonly == true {
				printFatal("The selected environment variable is readonly")
			} else {
				existing = true
			}
		}
	}

	fmt.Println("Please wait while your environment variable setting is applied...")

	asyncId, err := startEnvVarSet(stack.Uid, key, value, existing)
	if err != nil {
		printFatal(err.Error())
	}
	genericRes, err := endEnvVarSet(*asyncId, stack.Uid)
	if err != nil {
		printFatal(err.Error())
	}
	printGenericResponse(*genericRes)

	return
}
開發者ID:sgtpepper43,項目名稱:cx,代碼行數:47,代碼來源:env-vars-set.go


注:本文中的github.com/cloud66/cli.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。