github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/releases/contract.go (about) 1 package releases 2 3 import ( 4 "github.com/Sirupsen/logrus" 5 "github.com/daticahealth/cli/commands/services" 6 "github.com/daticahealth/cli/config" 7 "github.com/daticahealth/cli/lib/auth" 8 "github.com/daticahealth/cli/lib/prompts" 9 "github.com/daticahealth/cli/models" 10 "github.com/jault3/mow.cli" 11 ) 12 13 // Cmd for keys 14 var Cmd = models.Command{ 15 Name: "releases", 16 ShortHelp: "Manage releases for code services", 17 LongHelp: "The <code>releases</code> command allows you to manage your code service releases. " + 18 "A release is automatically created each time you perform a git push. " + 19 "The release is tagged with the git SHA of the commit. " + 20 "Releases are a way of tagging specific points in time of your git history. " + 21 "By default, the last three releases will be kept. " + 22 "Please contact Support if you require more than the last three releases to be retained. " + 23 "You can rollback to a specific release by using the rollback command. " + 24 "The releases command cannot be run directly but has subcommands.", 25 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 26 return func(cmd *cli.Cmd) { 27 cmd.CommandLong(ListSubCmd.Name, ListSubCmd.ShortHelp, ListSubCmd.LongHelp, ListSubCmd.CmdFunc(settings)) 28 cmd.CommandLong(RmSubCmd.Name, RmSubCmd.ShortHelp, RmSubCmd.LongHelp, RmSubCmd.CmdFunc(settings)) 29 cmd.CommandLong(UpdateSubCmd.Name, UpdateSubCmd.ShortHelp, UpdateSubCmd.LongHelp, UpdateSubCmd.CmdFunc(settings)) 30 } 31 }, 32 } 33 34 var ListSubCmd = models.Command{ 35 Name: "list", 36 ShortHelp: "List all releases for a given code service", 37 LongHelp: "<code>releases list</code> lists all of the releases for a given service. " + 38 "A release is automatically created each time a git push is performed. " + 39 "Here is a sample command\n\n" + 40 "<pre>\ndatica -E \"<your_env_name>\" releases list code-1\n</pre>", 41 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 42 return func(cmd *cli.Cmd) { 43 serviceName := cmd.StringArg("SERVICE_NAME", "", "The name of the service to list releases for") 44 cmd.Action = func() { 45 if _, err := auth.New(settings, prompts.New()).Signin(); err != nil { 46 logrus.Fatal(err.Error()) 47 } 48 if err := config.CheckRequiredAssociation(settings); err != nil { 49 logrus.Fatal(err.Error()) 50 } 51 err := CmdList(*serviceName, New(settings), services.New(settings)) 52 if err != nil { 53 logrus.Fatal(err) 54 } 55 } 56 } 57 }, 58 } 59 60 var RmSubCmd = models.Command{ 61 Name: "rm", 62 ShortHelp: "Remove a release from a code service", 63 LongHelp: "<code>releases rm</code> removes an existing release. This is useful in the case of a misbehaving code service. " + 64 "Removing the release avoids the risk of rolling back to a \"bad\" build. Here is a sample command\n\n" + 65 "<pre>\ndatica -E \"<your_env_name>\" releases rm code-1 f93ced037f828dcaabccfc825e6d8d32cc5a1883\n</pre>", 66 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 67 return func(cmd *cli.Cmd) { 68 serviceName := cmd.StringArg("SERVICE_NAME", "", "The name of the service to remove a release from") 69 releaseName := cmd.StringArg("RELEASE_NAME", "", "The name of the release to remove") 70 cmd.Action = func() { 71 if _, err := auth.New(settings, prompts.New()).Signin(); err != nil { 72 logrus.Fatal(err.Error()) 73 } 74 if err := config.CheckRequiredAssociation(settings); err != nil { 75 logrus.Fatal(err.Error()) 76 } 77 err := CmdRm(*serviceName, *releaseName, New(settings), services.New(settings)) 78 if err != nil { 79 logrus.Fatal(err) 80 } 81 } 82 } 83 }, 84 } 85 86 var UpdateSubCmd = models.Command{ 87 Name: "update", 88 ShortHelp: "Update a release from a code service", 89 LongHelp: "<code>releases update</code> allows you to rename or add notes to an existing release. " + 90 "By default, releases are named with the git SHA of the commit used to create the release. " + 91 "Renaming them allows you to organize your releases. Here is a sample command\n\n" + 92 "<pre>\ndatica -E \"<your_env_name>\" releases update code-1 f93ced037f828dcaabccfc825e6d8d32cc5a1883 --notes \"This is a stable build\"\n</pre>", 93 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 94 return func(cmd *cli.Cmd) { 95 serviceName := cmd.StringArg("SERVICE_NAME", "", "The name of the service to update a release for") 96 releaseName := cmd.StringArg("RELEASE_NAME", "", "The name of the release to update") 97 notes := cmd.StringOpt("n notes", "", "The new notes to save on the release.") 98 cmd.Action = func() { 99 if _, err := auth.New(settings, prompts.New()).Signin(); err != nil { 100 logrus.Fatal(err.Error()) 101 } 102 if err := config.CheckRequiredAssociation(settings); err != nil { 103 logrus.Fatal(err.Error()) 104 } 105 err := CmdUpdate(*serviceName, *releaseName, *notes, New(settings), services.New(settings)) 106 if err != nil { 107 logrus.Fatal(err) 108 } 109 } 110 cmd.Spec = "SERVICE_NAME RELEASE_NAME [--notes]" 111 } 112 }, 113 } 114 115 type IReleases interface { 116 List(svcID string) (*[]models.Release, error) 117 Retrieve(releaseName, svcID string) (*models.Release, error) 118 Rm(releaseName, svcID string) error 119 Update(releaseName, svcID, notes string) error 120 } 121 122 type SReleases struct { 123 Settings *models.Settings 124 } 125 126 func New(settings *models.Settings) IReleases { 127 return &SReleases{Settings: settings} 128 }