@@ -17,10 +17,11 @@ func GenerateResourcesCommand() *cobra.Command {
1717 }
1818
1919 resourcesCreateCmd := GenerateResourceCreateCommand ()
20+ resourcesUpdateCmd := GenerateResourceUpdateCommand ()
2021 resourcesDeleteCmd := GenerateResourceDeleteCommand ()
2122 resourcesGetCmd := GenerateResourcesGetCommand ()
2223
23- resourcesCmd .AddCommand (resourcesCreateCmd , resourcesDeleteCmd , resourcesGetCmd )
24+ resourcesCmd .AddCommand (resourcesCreateCmd , resourcesUpdateCmd , resourcesDeleteCmd , resourcesGetCmd )
2425
2526 return resourcesCmd
2627}
@@ -62,6 +63,48 @@ func GenerateResourceCreateCommand() *cobra.Command {
6263 return resourceCreateCmd
6364}
6465
66+ type resourceUpdateArg struct {
67+ Update interface {} `json:"update"`
68+ DropKeys []string `json:"drop_keys"`
69+ }
70+
71+ func GenerateResourceUpdateCommand () * cobra.Command {
72+ var token , resourceId string
73+ resourceUpdateCmd := & cobra.Command {
74+ Use : "update [resource]" ,
75+ Short : "Update resource" ,
76+ PreRunE : cmdutils .TokenArgPopulator ,
77+ RunE : func (cmd * cobra.Command , args []string ) error {
78+ if len (args ) != 1 {
79+ return fmt .Errorf (`One resource argument as json string in format {"update": {"key": "value"}, drop_keys: ["key"]} must be specified` )
80+ }
81+ var resourceUpdateRaw resourceUpdateArg
82+ err := json .Unmarshal ([]byte (args [0 ]), & resourceUpdateRaw )
83+ if err != nil {
84+ return err
85+ }
86+
87+ client , clientErr := bugout .ClientFromEnv ()
88+ if clientErr != nil {
89+ return clientErr
90+ }
91+
92+ resource , err := client .Brood .UpdateResource (token , resourceId , resourceUpdateRaw .Update , resourceUpdateRaw .DropKeys )
93+ if err != nil {
94+ return err
95+ }
96+
97+ encodeErr := json .NewEncoder (cmd .OutOrStdout ()).Encode (& resource )
98+ return encodeErr
99+ },
100+ }
101+
102+ resourceUpdateCmd .Flags ().StringVarP (& token , "token" , "t" , "" , "Bugout access token to use for the request" )
103+ resourceUpdateCmd .Flags ().StringVarP (& resourceId , "resource_id" , "r" , "" , "Resource ID" )
104+
105+ return resourceUpdateCmd
106+ }
107+
65108func GenerateResourceDeleteCommand () * cobra.Command {
66109 var token , resourceId string
67110 resourceDeleteCmd := & cobra.Command {
0 commit comments