44 "fmt"
55
66 "github.com/hokaccha/go-prettyjson"
7+ log "github.com/sirupsen/logrus"
78 "github.com/spf13/cobra"
89
910 "github.com/newrelic/newrelic-client-go/newrelic"
@@ -39,8 +40,13 @@ The list command returns deployments for a New Relic APM application.
3940` ,
4041 Example : "newrelic apm deployment list --applicationId <appID>" ,
4142 Run : func (cmd * cobra.Command , args []string ) {
43+ if apmAppID == 0 {
44+ utils .LogIfError (cmd .Help ())
45+ log .Fatal ("--applicationId is required" )
46+ }
47+
4248 client .WithClient (func (nrClient * newrelic.NewRelic ) {
43- deployments , err := nrClient .APM .ListDeployments (appID )
49+ deployments , err := nrClient .APM .ListDeployments (apmAppID )
4450 utils .LogIfFatal (err )
4551
4652 json , err := prettyjson .Marshal (deployments )
@@ -61,8 +67,13 @@ application.
6167` ,
6268 Example : "newrelic apm deployment create --applicationId <appID> --revision <deploymentRevision>" ,
6369 Run : func (cmd * cobra.Command , args []string ) {
70+ if apmAppID == 0 {
71+ utils .LogIfError (cmd .Help ())
72+ log .Fatal ("--applicationId and --revision are required" )
73+ }
74+
6475 client .WithClient (func (nrClient * newrelic.NewRelic ) {
65- d , err := nrClient .APM .CreateDeployment (appID , deployment )
76+ d , err := nrClient .APM .CreateDeployment (apmAppID , deployment )
6677 utils .LogIfFatal (err )
6778
6879 json , err := prettyjson .Marshal (d )
@@ -82,8 +93,13 @@ The delete command performs a delete operation for an APM deployment.
8293` ,
8394 Example : "newrelic apm deployment delete --applicationId <appID> --deploymentID <deploymentID>" ,
8495 Run : func (cmd * cobra.Command , args []string ) {
96+ if apmAppID == 0 {
97+ utils .LogIfError (cmd .Help ())
98+ log .Fatal ("--applicationId is required" )
99+ }
100+
85101 client .WithClient (func (nrClient * newrelic.NewRelic ) {
86- d , err := nrClient .APM .DeleteDeployment (appID , deployment .ID )
102+ d , err := nrClient .APM .DeleteDeployment (apmAppID , deployment .ID )
87103 utils .LogIfFatal (err )
88104
89105 json , err := prettyjson .Marshal (d )
@@ -98,24 +114,16 @@ func init() {
98114 Command .AddCommand (cmdDeployment )
99115
100116 cmdDeployment .AddCommand (cmdDeploymentList )
101- cmdDeploymentList .Flags ().IntVarP (& appID , "applicationId" , "a" , 0 , "the application ID to list deployments for" )
102- utils .LogIfError (cmdDeploymentList .MarkFlagRequired ("applicationId" ))
103117
104118 cmdDeployment .AddCommand (cmdDeploymentCreate )
105119 cmdDeploymentCreate .Flags ().StringVarP (& deployment .Description , "description" , "" , "" , "the description stored with the deployment" )
106120 cmdDeploymentCreate .Flags ().StringVarP (& deployment .User , "user" , "" , "" , "the user creating with the deployment" )
107121 cmdDeploymentCreate .Flags ().StringVarP (& deployment .Changelog , "change-log" , "" , "" , "the change log stored with the deployment" )
108122
109- cmdDeploymentCreate .Flags ().IntVarP (& appID , "applicationId" , "a" , 0 , "the application ID the deployment will be created for" )
110- utils .LogIfError (cmdDeploymentCreate .MarkFlagRequired ("applicationId" ))
111-
112123 cmdDeploymentCreate .Flags ().StringVarP (& deployment .Revision , "revision" , "r" , "" , "a freeform string representing the revision of the deployment" )
113124 utils .LogIfError (cmdDeploymentCreate .MarkFlagRequired ("revision" ))
114125
115126 cmdDeployment .AddCommand (cmdDeploymentDelete )
116- cmdDeploymentDelete .Flags ().IntVarP (& appID , "applicationId" , "a" , 0 , "the application ID the deployment belongs to" )
117- utils .LogIfError (cmdDeploymentDelete .MarkFlagRequired ("applicationId" ))
118-
119127 cmdDeploymentDelete .Flags ().IntVarP (& deployment .ID , "deploymentID" , "d" , 0 , "the ID of the deployment to be deleted" )
120128 utils .LogIfError (cmdDeploymentDelete .MarkFlagRequired ("deploymentID" ))
121129}
0 commit comments