MCPcopy
hub / github.com/larksuite/cli / runExistingAppForm

Function runExistingAppForm

cmd/config/init_interactive.go:61–147  ·  view source on GitHub ↗

runExistingAppForm shows a huh form for manually entering App ID / App Secret / Brand.

(f *cmdutil.Factory, msg *initMsg)

Source from the content-addressed store, hash-verified

59
60// runExistingAppForm shows a huh form for manually entering App ID / App Secret / Brand.
61func runExistingAppForm(f *cmdutil.Factory, msg *initMsg) (*configInitResult, error) {
62 // Load existing config for defaults
63 existing, _ := core.LoadMultiAppConfig()
64 var firstApp *core.AppConfig
65 if existing != nil {
66 firstApp = existing.CurrentAppConfig("")
67 }
68
69 var appID, appSecret, brand string
70
71 appIDInput := huh.NewInput().
72 Title("App ID").
73 Value(&appID)
74 if firstApp != nil && firstApp.AppId != "" {
75 appIDInput = appIDInput.Placeholder(firstApp.AppId)
76 } else {
77 appIDInput = appIDInput.Placeholder("cli_xxxx")
78 }
79
80 appSecretInput := huh.NewInput().
81 Title("App Secret").
82 EchoMode(huh.EchoModePassword).
83 Value(&appSecret)
84 if firstApp != nil && !firstApp.AppSecret.IsZero() {
85 appSecretInput = appSecretInput.Placeholder("****")
86 } else {
87 appSecretInput = appSecretInput.Placeholder("xxxx")
88 }
89
90 brand = "feishu"
91 if firstApp != nil && firstApp.Brand != "" {
92 brand = string(firstApp.Brand)
93 }
94
95 form := huh.NewForm(
96 huh.NewGroup(
97 appIDInput,
98 appSecretInput,
99 huh.NewSelect[string]().
100 Title(msg.Platform).
101 Options(
102 huh.NewOption(msg.Feishu, "feishu"),
103 huh.NewOption("Lark", "lark"),
104 ).
105 Value(&brand),
106 ),
107 ).WithTheme(cmdutil.ThemeFeishu())
108
109 if err := form.Run(); err != nil {
110 if err == huh.ErrUserAborted {
111 return nil, output.ErrBare(1)
112 }
113 return nil, err
114 }
115
116 // Resolve defaults
117 if appID == "" && firstApp != nil {
118 appID = firstApp.AppId

Callers 1

runInteractiveConfigInitFunction · 0.85

Calls 9

LoadMultiAppConfigFunction · 0.92
ThemeFeishuFunction · 0.92
ErrBareFunction · 0.92
NewValidationErrorFunction · 0.92
parseBrandFunction · 0.85
CurrentAppConfigMethod · 0.80
WithParamMethod · 0.80
RunMethod · 0.65
IsZeroMethod · 0.45

Tested by

no test coverage detected