本文整理匯總了Golang中github.com/cloud66/cli.Context.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.String方法的具體用法?Golang Context.String怎麽用?Golang Context.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloud66/cli.Context
的用法示例。
在下文中一共展示了Context.String方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: 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)
}
}
示例3: 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)
}
示例4: 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())
}
}
示例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())
}
示例6: 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)
}
示例7: runRun
func runRun(c *cli.Context) {
if runtime.GOOS == "windows" {
printFatal("Not supported on Windows")
os.Exit(2)
}
stack := mustStack(c)
if c.String("service") != "" && stack.Framework != "docker" {
printFatal("The service option only applies to docker stacks")
os.Exit(2)
}
serverName := c.String("server")
if !c.IsSet("service") {
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "run")
os.Exit(2)
}
}
userCommand := ""
if len(c.Args()) == 1 {
userCommand = c.Args()[0]
}
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")
}
if c.String("service") != "" {
// fetch service information for existing server/command
service, err := client.GetService(stack.Uid, c.String("service"), &server.Uid, &userCommand)
must(err)
userCommand = service.WrapCommand
}
includeTty := c.String("service") != ""
err = SshToServerForCommand(*server, userCommand, includeTty)
if err != nil {
printFatal(err.Error())
}
}
示例8: 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())
}
}
示例9: 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)
}
示例10: runLease
func runLease(c *cli.Context) {
stack := mustStack(c)
from := c.String("from")
tto := c.Int("tto")
port := c.Int("port")
fmt.Printf("Attempting to lease from %s to port %d for %d minutes...\n", from, port, tto)
genericRes, err := client.LeaseSync(stack.Uid, &from, &tto, &port, nil)
if err != nil {
printFatal(err.Error())
}
printGenericResponse(*genericRes)
}
示例11: 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
}
}
示例12: 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)
}
}
示例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: runServerSet
func runServerSet(c *cli.Context) {
fmt.Println(c.Args())
stack := mustStack(c)
if len(c.Args()) != 1 {
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
// get the server
args := c.Args()
serverName := c.String("server")
// filter out the server name
kvs := args[0]
kva := strings.Split(kvs, "=")
if len(kva) != 2 {
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
key := kva[0]
value := kva[1]
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)
executeServerSet(*stack, *server, c, key, value)
}