55 "log"
66
77 "github.com/pushbits/cli/internal/api"
8- "github.com/pushbits/cli/internal/settings "
8+ "github.com/pushbits/cli/internal/options "
99 "github.com/pushbits/cli/internal/ui"
1010)
1111
@@ -14,20 +14,16 @@ const (
1414)
1515
1616type updateCommand struct {
17- Arguments struct {
18- ID uint `required:"true" positional-arg-name:"id" description:"The ID of the application"`
19- } `positional-args:"true"`
20- NewName * string `long:"new-name" description:"The new name of the application"`
21- RefreshToken bool `long:"refresh" description:"Refresh the token of the application"`
22- StrictCompatibility bool `long:"compat" description:"Enforce strict compatibility with Gotify"`
17+ options.AuthOptions
18+ ID uint `arg:"" help:"The ID of the application"`
19+ NewName string `long:"new-name" help:"The new name of the application" optional:""`
20+ RefreshToken bool `long:"refresh" help:"Refresh the token of the application"`
21+ StrictCompatibility bool `long:"compat" help:"Enforce strict compatibility with Gotify"`
2322}
2423
25- func (c * updateCommand ) Execute (args []string ) error {
26- settings .Runner = c
27- return nil
28- }
24+ func (c * updateCommand ) Run (s * options.Options ) error {
25+ password := ui .GetCurrentPassword (c .Username )
2926
30- func (c * updateCommand ) Run (s * settings.Settings , password string ) {
3127 if ! c .RefreshToken && c .StrictCompatibility {
3228 log .Fatal ("Can only enforce compatibility when refreshing the token of the application" )
3329 }
@@ -37,16 +33,18 @@ func (c *updateCommand) Run(s *settings.Settings, password string) {
3733 "strict_compatibility" : c .StrictCompatibility ,
3834 }
3935
40- if c .NewName != nil {
36+ if len ( c .NewName ) > 0 {
4137 data ["new_name" ] = c .NewName
4238 }
4339
44- populatedEndpoint := fmt .Sprintf (updateEndpoint , c .Arguments . ID )
40+ populatedEndpoint := fmt .Sprintf (updateEndpoint , c .ID )
4541
46- resp , err := api .Put (s .URL , populatedEndpoint , s .Proxy , s .Username , password , data )
42+ resp , err := api .Put (c .URL , populatedEndpoint , c .Proxy , c .Username , password , data )
4743 if err != nil {
4844 log .Fatal (err )
4945 }
5046
5147 ui .PrintJSON (resp )
48+
49+ return nil
5250}
0 commit comments