runExistingAppForm shows a huh form for manually entering App ID / App Secret / Brand.
(f *cmdutil.Factory, msg *initMsg)
| 59 | |
| 60 | // runExistingAppForm shows a huh form for manually entering App ID / App Secret / Brand. |
| 61 | func 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 |
no test coverage detected