本文整理汇总了Golang中github.com/catalyzeio/cli/lib/prompts.IPrompts类的典型用法代码示例。如果您正苦于以下问题:Golang IPrompts类的具体用法?Golang IPrompts怎么用?Golang IPrompts使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPrompts类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CmdDownload
func CmdDownload(databaseName, backupID, filePath string, force bool, id IDb, ip prompts.IPrompts, is services.IServices) error {
err := ip.PHI()
if err != nil {
return err
}
if !force {
if _, err := os.Stat(filePath); err == nil {
return fmt.Errorf("File already exists at path '%s'. Specify `--force` to overwrite", filePath)
}
} else {
os.Remove(filePath)
}
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
err = id.Download(backupID, filePath, service)
if err != nil {
return err
}
logrus.Printf("%s backup downloaded successfully to %s", databaseName, filePath)
logrus.Printf("You can also view logs for this backup with the \"catalyze db logs %s %s\" command", databaseName, backupID)
return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:27,代码来源:download.go
示例2: CmdRm
func CmdRm(svcName, target string, iw IWorker, is services.IServices, ip prompts.IPrompts, ij jobs.IJobs) error {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
}
err = ip.YesNo(fmt.Sprintf("Removing the worker target %s for service %s will automatically stop all existing worker jobs with that target, would you like to proceed? (y/n) ", target, svcName))
if err != nil {
return err
}
jobs, err := ij.RetrieveByTarget(service.ID, target, 1, 1000)
if err != nil {
return err
}
for _, j := range *jobs {
err = ij.Delete(j.ID, service.ID)
if err != nil {
return err
}
}
workers, err := iw.Retrieve(service.ID)
if err != nil {
return err
}
delete(workers.Workers, target)
err = iw.Update(service.ID, workers)
if err != nil {
return err
}
logrus.Printf("Successfully removed all workers with target %s for service %s", target, svcName)
return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:34,代码来源:rm.go
示例3: CmdExport
func CmdExport(databaseName, filePath string, force bool, id IDb, ip prompts.IPrompts, is services.IServices, ij jobs.IJobs) error {
err := ip.PHI()
if err != nil {
return err
}
if !force {
if _, err := os.Stat(filePath); err == nil {
return fmt.Errorf("File already exists at path '%s'. Specify `--force` to overwrite", filePath)
}
} else {
os.Remove(filePath)
}
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
job, err := id.Backup(service)
if err != nil {
return err
}
logrus.Printf("Export started (job ID = %s)", job.ID)
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte("Polling until export finishes."))
status, err := ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nEnded in status '%s'", job.Status)
if job.Status != "finished" {
id.DumpLogs("backup", job, service)
return fmt.Errorf("Job finished with invalid status %s", job.Status)
}
err = id.Export(filePath, job, service)
if err != nil {
return err
}
err = id.DumpLogs("backup", job, service)
if err != nil {
return err
}
logrus.Printf("%s exported successfully to %s", service.Name, filePath)
return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:48,代码来源:export.go
示例4: CmdAccept
// CmdAccept creates an environment from a JSON env spec
func CmdAccept(inviteCode string, ii IInvites, ia auth.IAuth, ip prompts.IPrompts) error {
user, err := ia.Signin()
if err != nil {
return err
}
err = ip.YesNo(fmt.Sprintf("Are you sure you want to accept this org invitation as %s? (y/n) ", user.Email))
if err != nil {
return err
}
orgID, err := ii.Accept(inviteCode)
if err != nil {
return err
}
logrus.Printf("Successfully joined organization (%s) as %s\n", orgID, user.Email)
return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:18,代码来源:accept.go
示例5: CmdStop
// CmdStop stops all instances of a given service. All workers and rake tasks will also be stopped
// if applicable.
func CmdStop(svcName string, is IServices, ij jobs.IJobs, ip prompts.IPrompts) error {
err := ip.YesNo(fmt.Sprintf("Are you sure you want to stop %s? This will stop all instances of the service, all workers, all rake tasks, and all currently open consoles. (y/n) ", svcName))
if err != nil {
return err
}
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
}
if !service.Redeployable {
return fmt.Errorf("This service cannot be stopped. Please contact Catalyze Support at [email protected] if you need the \"%s\" service stopped.", svcName)
}
page := 0
pageSize := 100
for {
jobs, err := ij.List(service.ID, page, pageSize)
if err != nil {
return err
}
for _, job := range *jobs {
if job.Status != "scheduled" && job.Status != "queued" && job.Status != "started" && job.Status != "running" && job.Status != "waiting" {
logrus.Debugf("Skipping %s job (%s)", job.Status, job.ID)
continue
}
logrus.Debugf("Deleting %s job (%s) on service %s", job.Type, job.ID, service.ID)
err = ij.Delete(job.ID, service.ID)
if err != nil {
return err
}
}
if len(*jobs) < pageSize {
break
}
page++
}
logrus.Printf("Successfully stopped %s. Run \"catalyze redeploy %s\" to start this service again.", svcName, svcName)
return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:46,代码来源:stop.go
示例6: CmdSend
func CmdSend(email, envName, roleName string, ii IInvites, ip prompts.IPrompts) error {
err := ip.YesNo(fmt.Sprintf("Are you sure you want to invite %s to your %s organization? (y/n) ", email, envName))
if err != nil {
return err
}
roles, err := ii.ListRoles()
if err != nil {
return err
}
role := 5
for _, r := range *roles {
if strings.ToLower(r.Name) == strings.ToLower(roleName) {
role = r.ID
break
}
}
err = ii.Send(email, role)
if err != nil {
return err
}
logrus.Printf("%s has been invited!", email)
return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:23,代码来源:send.go
示例7: CmdScale
func CmdScale(svcName, target, scaleString string, iw IWorker, is services.IServices, ip prompts.IPrompts, ij jobs.IJobs) error {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
}
scaleFunc, changeInScale, err := iw.ParseScale(scaleString)
if err != nil {
return err
}
workers, err := iw.Retrieve(service.ID)
if err != nil {
return err
}
scale := scaleFunc(workers.Workers[target], changeInScale)
if existingScale, ok := workers.Workers[target]; !ok || scale > existingScale {
logrus.Printf("Deploying %d new workers with target %s for service %s", scale-existingScale, target, svcName)
workers.Workers[target] = scale
err = iw.Update(service.ID, workers)
if err != nil {
return err
}
err = ij.DeployTarget(target, service.ID)
if err != nil {
return err
}
logrus.Printf("Successfully deployed %d new workers with target %s for service %s and set the scale to %d", scale-existingScale, target, svcName, scale)
} else if scale < existingScale {
err = ip.YesNo(fmt.Sprintf("Scaling down the %s target from %d to %d for service %s will automatically stop %d jobs, would you like to proceed? (y/n) ", target, existingScale, scale, svcName, existingScale-scale))
if err != nil {
return err
}
jobs, err := ij.RetrieveByTarget(service.ID, target, 1, 1000)
if err != nil {
return err
}
deleteLimit := existingScale - scale
deleted := 0
for _, j := range *jobs {
err = ij.Delete(j.ID, service.ID)
if err != nil {
return err
}
deleted++
if deleted == deleteLimit {
break
}
}
workers.Workers[target] = scale
err = iw.Update(service.ID, workers)
if err != nil {
return err
}
logrus.Printf("Successfully removed %d existing workers with target %s for service %s and set the scale to %d", existingScale-scale, target, svcName, scale)
} else {
logrus.Printf("Worker target %s for service %s is already at a scale of %d", target, svcName, scale)
}
return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:62,代码来源:scale.go
注:本文中的github.com/catalyzeio/cli/lib/prompts.IPrompts类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论