1717 actionFlag string
1818 assigneeFlag uint64
1919 attachFlag string
20+ descriptionFlag string
2021 dryRunUpdateWorkPackage bool
2122 printUpdatedWorkPackageAsJSON bool
2223 setFlags []string
@@ -100,17 +101,55 @@ func updateWorkPackage(_ *cobra.Command, args []string) {
100101 return
101102 }
102103
103- if printUpdatedWorkPackageAsJSON || dryRunUpdateWorkPackage {
104+ options := updateOptions ()
105+ if len (options ) == 0 {
104106 printUpdateError ("invalid_argument" , "--json and --dry-run currently require at least one --set value" )
105107 return
106108 }
107109
108- if workPackage , err := work_packages .Update (id , updateOptions ()); err == nil {
109- printer .Info ("-- " )
110- printer .WorkPackage (workPackage )
111- } else {
110+ if dryRunUpdateWorkPackage {
111+ plan := work_packages .DryRunUpdate (id , options )
112+
113+ data , err := presenter .MarshalJSON (plan )
114+ if err != nil {
115+ printer .Error (err )
116+ return
117+ }
118+
119+ printer .Info (string (data ))
120+ return
121+ }
122+
123+ workPackage , err := work_packages .Update (id , options )
124+ if err != nil {
125+ if printUpdatedWorkPackageAsJSON {
126+ printUpdateError ("api_error" , err .Error ())
127+ return
128+ }
129+
112130 printer .Error (err )
131+ return
113132 }
133+
134+ if printUpdatedWorkPackageAsJSON {
135+ payload , err := work_packages .Inspect (id )
136+ if err != nil {
137+ printUpdateError ("api_error" , err .Error ())
138+ return
139+ }
140+
141+ data , err := presenter .MarshalJSON (payload )
142+ if err != nil {
143+ printer .Error (err )
144+ return
145+ }
146+
147+ printer .Info (string (data ))
148+ return
149+ }
150+
151+ printer .Info ("-- " )
152+ printer .WorkPackage (workPackage )
114153}
115154
116155func updateOptions () map [work_packages.UpdateOption ]string {
@@ -127,6 +166,9 @@ func updateOptions() map[work_packages.UpdateOption]string {
127166 if len (subjectFlag ) > 0 {
128167 options [work_packages .UpdateSubject ] = subjectFlag
129168 }
169+ if len (descriptionFlag ) > 0 {
170+ options [work_packages .UpdateDescription ] = descriptionFlag
171+ }
130172 if len (typeFlag ) > 0 {
131173 options [work_packages .UpdateType ] = typeFlag
132174 }
@@ -139,6 +181,13 @@ func validateUpdateWorkPackageFlags() error {
139181 return fmt .Errorf ("cannot use --dry-run without --json" )
140182 }
141183
184+ if len (descriptionFlag ) > 0 {
185+ conflicts := activeDescriptionConflicts ()
186+ if len (conflicts ) > 0 {
187+ return fmt .Errorf ("cannot combine --description with %s" , strings .Join (conflicts , ", " ))
188+ }
189+ }
190+
142191 if len (setFlags ) > 0 && hasLegacyUpdateFlags () {
143192 return fmt .Errorf ("cannot combine --set with %s" , strings .Join (activeLegacyUpdateFlags (), ", " ))
144193 }
@@ -165,13 +214,29 @@ func activeLegacyUpdateFlags() []string {
165214 if len (subjectFlag ) > 0 {
166215 flags = append (flags , "--subject" )
167216 }
217+ if len (descriptionFlag ) > 0 {
218+ flags = append (flags , "--description" )
219+ }
168220 if len (typeFlag ) > 0 {
169221 flags = append (flags , "--type" )
170222 }
171223
172224 return flags
173225}
174226
227+ func activeDescriptionConflicts () []string {
228+ flags := []string {}
229+
230+ if len (actionFlag ) > 0 {
231+ flags = append (flags , "--action" )
232+ }
233+ if len (attachFlag ) > 0 {
234+ flags = append (flags , "--attach" )
235+ }
236+
237+ return flags
238+ }
239+
175240func printUpdateError (code , message string ) {
176241 if ! printUpdatedWorkPackageAsJSON {
177242 printer .ErrorText (message )
0 commit comments