本文整理匯總了Golang中github.com/cloud66/cli.Context.Args方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Args方法的具體用法?Golang Context.Args怎麽用?Golang Context.Args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloud66/cli.Context
的用法示例。
在下文中一共展示了Context.Args方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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)
}
示例3: 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)
}
}
示例4: 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)
}
}
示例5: 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)
}
示例6: 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)
}
}
}
示例7: 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())
}
示例8: 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)
}
}
示例9: beforeCommand
func beforeCommand(c *cli.Context) error {
// set the env vars from global options
if c.GlobalString("runenv") != "production" {
tokenFile = "cx_" + c.GlobalString("runenv") + ".json"
fmt.Printf(ansi.Color(fmt.Sprintf("Running against %s environment\n", c.GlobalString("runenv")), "grey"))
honeybadger.Environment = c.GlobalString("runenv")
} else {
honeybadger.Environment = "production"
}
if c.GlobalString("fayeEndpoint") != "" {
fayeEndpoint = c.GlobalString("fayeEndpoint")
}
debugMode = c.GlobalBool("debug")
var command string
if len(c.Args()) >= 1 {
command = c.Args().First()
}
if (command != "version") && (command != "help") && (command != "update") {
initClients(c)
}
if (command != "update") && (VERSION != "dev") {
defer backgroundRun()
}
return nil
}
示例10: 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())
}
}
示例11: runJobRun
func runJobRun(c *cli.Context) {
stack := mustStack(c)
// get the job
if len(c.Args()) != 1 {
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
jobName := c.Args()[0]
jobs, err := client.GetJobs(stack.Uid, nil)
if err != nil {
printFatal(err.Error())
}
var jobNames []string
for _, job := range jobs {
jobNames = append(jobNames, job.GetBasicJob().Name)
}
idx, err := fuzzyFind(jobNames, jobName, false)
if err != nil {
printFatal(err.Error())
}
jobUid := string(jobs[idx].GetBasicJob().Uid)
jobArgs := ""
if len(c.StringSlice("arg")) > 0 {
for i, arg := range c.StringSlice("arg") {
if i > 0 {
jobArgs = jobArgs + " "
}
jobArgs = jobArgs + "\"" + arg + "\""
}
}
asyncId, err := startJobRun(stack.Uid, jobUid, &jobArgs)
if err != nil {
printFatal(err.Error())
}
genericRes, err := endJobRun(*asyncId, stack.Uid)
if err != nil {
printFatal(err.Error())
}
printGenericResponse(*genericRes)
return
}
示例12: 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
}
示例13: 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)
}
示例14: runServiceStop
func runServiceStop(c *cli.Context) {
if len(c.Args()) != 1 {
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
stack := mustStack(c)
serviceName := c.Args()[0]
flagServer := c.String("server")
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
}
asyncId, err := startServiceStop(stack.Uid, serviceName, serverUid)
if err != nil {
printFatal(err.Error())
}
genericRes, err := endServiceStop(*asyncId, stack.Uid)
if err != nil {
printFatal(err.Error())
}
printGenericResponse(*genericRes)
return
}
示例15: runServiceInfo
func runServiceInfo(c *cli.Context) {
if len(c.Args()) != 1 {
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
stack := mustStack(c)
serviceName := c.Args()[0]
flagServer := c.String("server")
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 + "' is not a docker server")
}
fmt.Printf("Server: %s\n", server.Name)
serverUid = &server.Uid
}
service, err := client.GetService(stack.Uid, serviceName, serverUid, nil)
must(err)
printServiceInfoList(w, service)
return
}