| 64 | } |
| 65 | |
| 66 | func runUpdateCmd(opts *UpdateOptions) error { |
| 67 | cs := opts.IO.ColorScheme() |
| 68 | |
| 69 | appID, err := opts.Config.Profile().GetApplicationID() |
| 70 | if err != nil { |
| 71 | return fmt.Errorf( |
| 72 | "no current application configured; configure a profile with \"algolia profile add\" or \"algolia application select\" first: %w", |
| 73 | err, |
| 74 | ) |
| 75 | } |
| 76 | |
| 77 | client := opts.NewDashboardClient(auth.OAuthClientID()) |
| 78 | |
| 79 | accessToken, err := auth.EnsureAuthenticated(opts.IO, client) |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | |
| 84 | opts.IO.StartProgressIndicatorWithLabel("Updating application") |
| 85 | app, err := client.UpdateApplication(accessToken, appID, opts.Name) |
| 86 | opts.IO.StopProgressIndicator() |
| 87 | if err != nil { |
| 88 | newToken, reAuthErr := auth.ReauthenticateIfExpired(opts.IO, client, err) |
| 89 | if reAuthErr != nil { |
| 90 | return reAuthErr |
| 91 | } |
| 92 | accessToken = newToken |
| 93 | opts.IO.StartProgressIndicatorWithLabel("Updating application") |
| 94 | app, err = client.UpdateApplication(accessToken, appID, opts.Name) |
| 95 | opts.IO.StopProgressIndicator() |
| 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if opts.PrintFlags.OutputFlagSpecified() && opts.PrintFlags.OutputFormat != nil { |
| 102 | p, err := opts.PrintFlags.ToPrinter() |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | return p.Print(opts.IO, app) |
| 107 | } |
| 108 | |
| 109 | fmt.Fprintf( |
| 110 | opts.IO.Out, |
| 111 | "%s Application %s renamed to %q.\n", |
| 112 | cs.SuccessIcon(), |
| 113 | cs.Bold(app.ID), |
| 114 | app.Name, |
| 115 | ) |
| 116 | return nil |
| 117 | } |