本文整理汇总了Golang中github.com/cloud66/cli.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: runDownloadManifestYaml
func runDownloadManifestYaml(c *cli.Context, stackUid string) {
version := c.String("version")
if version == "" {
version = "latest"
}
manifestYaml, err := client.ManifestYamlInfo(stackUid, version)
must(err)
output := c.String("output")
if output != "" {
err := writeFile(output, manifestYaml.Body)
must(err)
} else {
fmt.Println(manifestYaml.Body)
}
}
开发者ID:sgtpepper43,项目名称:cx,代码行数:17,代码来源:stack-configure.go
示例17: runStacks
func runStacks(c *cli.Context) {
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
var stacks []cloud66.Stack
names := c.Args()
flagForcedEnvironment := c.String("environment")
if len(names) == 0 {
var err error
stacks, err = client.StackListWithFilter(func(item interface{}) bool {
if flagForcedEnvironment == "" {
return true
}
return strings.HasPrefix(strings.ToLower(item.(cloud66.Stack).Environment), strings.ToLower(flagForcedEnvironment))
})
must(err)
} else {
stackch := make(chan *cloud66.Stack, len(names))
errch := make(chan error, len(names))
for _, name := range names {
if name == "" {
stackch <- nil
} else {
go func(stackname string) {
if stack, err := client.StackInfoWithEnvironment(stackname, flagForcedEnvironment); err != nil {
errch <- err
} else {
stackch <- stack
}
}(name)
}
}
for _ = range names {
select {
case err := <-errch:
printFatal(err.Error())
case stack := <-stackch:
if stack != nil {
stacks = append(stacks, *stack)
}
}
}
}
printStackList(w, stacks)
}
开发者ID:sgtpepper43,项目名称:cx,代码行数:45,代码来源:stacks.go
示例18: runServerReboot
func runServerReboot(c *cli.Context) {
stack := mustStack(c)
if len(c.Args()) != 0 {
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
serverName := c.String("server")
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)
// confirmation is needed if the stack is production
if !c.Bool("y") {
mustConfirm("This operation will reboot your server during which time your server will not be available. Proceed with reboot? [yes/N]", "yes")
}
executeServerReboot(*stack, *server)
}
开发者ID:magiccreater,项目名称:cx,代码行数:31,代码来源:servers-reboot.go
示例19: runSet
func runSet(c *cli.Context) {
if len(c.Args()) != 2 {
//cmd.printUsage()
os.Exit(2)
}
key := c.Args()[0]
value := c.Args()[1]
stack := mustStack(c)
settings, err := client.StackSettings(stack.Uid)
must(err)
// check to see if it's a valid setting
for _, i := range settings {
if key == i.Key {
// yup. it's a good one
fmt.Printf("Please wait while your setting is applied...\n")
asyncId, err := startSet(stack.Uid, key, value)
if err != nil {
printFatal(err.Error())
}
genericRes, err := endSet(*asyncId, stack.Uid)
if err != nil {
printFatal(err.Error())
}
printGenericResponse(*genericRes)
return
}
}
printFatal(key + " is not a valid setting or does not apply to this stack")
}
开发者ID:sgtpepper43,项目名称:cx,代码行数:35,代码来源:settings-set.go
示例20: runContainers
func runContainers(c *cli.Context) {
stack := mustStack(c)
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
flagServer := c.String("server")
flagServiceName := c.String("service")
flagTruncate := c.Bool("trunc")
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")
}
fmt.Printf("Server: %s\n", server.Name)
serverUid = &server.Uid
}
containers, err := client.GetContainers(stack.Uid, serverUid, &flagServiceName)
must(err)
printContainerList(w, containers, flagTruncate)
}
开发者ID:sgtpepper43,项目名称:cx,代码行数:33,代码来源:containers.go
注:本文中的github.com/cloud66/cli.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论