MCPcopy Create free account
hub / github.com/algolia/cli / runUpdateCmd

Function runUpdateCmd

pkg/cmd/application/update/update.go:66–117  ·  view source on GitHub ↗
(opts *UpdateOptions)

Source from the content-addressed store, hash-verified

64}
65
66func 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}

Callers 3

NewUpdateCmdFunction · 0.70
Test_runUpdateCmdFunction · 0.70

Calls 14

OAuthClientIDFunction · 0.92
EnsureAuthenticatedFunction · 0.92
ReauthenticateIfExpiredFunction · 0.92
ColorSchemeMethod · 0.80
GetApplicationIDMethod · 0.80
UpdateApplicationMethod · 0.80
StopProgressIndicatorMethod · 0.80
SuccessIconMethod · 0.80
BoldMethod · 0.80
ProfileMethod · 0.65
ErrorfMethod · 0.65

Tested by 2

Test_runUpdateCmdFunction · 0.56