github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/rollback/rollback.go (about) 1 package rollback 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/Sirupsen/logrus" 8 "github.com/daticahealth/cli/commands/releases" 9 "github.com/daticahealth/cli/commands/services" 10 "github.com/daticahealth/cli/config" 11 "github.com/daticahealth/cli/lib/jobs" 12 ) 13 14 func CmdRollback(svcName, releaseName string, ij jobs.IJobs, irs releases.IReleases, is services.IServices) error { 15 if strings.ContainsAny(releaseName, config.InvalidChars) { 16 return fmt.Errorf("Invalid release name. Names must not contain the following characters: %s", config.InvalidChars) 17 } 18 service, err := is.RetrieveByLabel(svcName) 19 if err != nil { 20 return err 21 } 22 if service == nil { 23 return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"datica services list\" command.", svcName) 24 } 25 logrus.Printf("Rolling back %s to %s", svcName, releaseName) 26 release, err := irs.Retrieve(releaseName, service.ID) 27 if err != nil { 28 return err 29 } 30 if release == nil { 31 return fmt.Errorf("Could not find a release with the name \"%s\". You can list releases for this code service with the \"datica releases list %s\" command.", releaseName, svcName) 32 } 33 err = ij.DeployRelease(releaseName, service.ID) 34 if err != nil { 35 return err 36 } 37 logrus.Println("Rollback successful! Check the status with \"datica status\" and your logging dashboard for updates.") 38 return nil 39 }