-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add guided setup command #753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package setup | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
|
|
||
| tea "github.com/charmbracelet/bubbletea" | ||
|
|
||
| "github.com/launchdarkly/ldcli/internal/setup" | ||
| ) | ||
|
|
||
| func (m wizardModel) fetchProjects() tea.Cmd { | ||
| return func() tea.Msg { | ||
| ps, err := m.svc.ListProjects(m.auth) | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| projects := make([]projectItem, len(ps)) | ||
| for i, p := range ps { | ||
| projects[i] = projectItem{key: p.Key, name: p.Name} | ||
| } | ||
| return projectsFetchedMsg{projects: projects} | ||
| } | ||
| } | ||
|
|
||
| func (m wizardModel) fetchEnvironments() tea.Cmd { | ||
| return func() tea.Msg { | ||
| es, err := m.svc.ListEnvironments(m.auth, m.selectedProject) | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| envs := make([]envItem, len(es)) | ||
| for i, e := range es { | ||
| envs[i] = envItem{key: e.Key, name: e.Name} | ||
| } | ||
| return envsFetchedMsg{environments: envs} | ||
| } | ||
| } | ||
|
|
||
| func (m wizardModel) fetchEnvDetails() tea.Cmd { | ||
| return func() tea.Msg { | ||
| keys, err := m.svc.EnvKeys(m.auth, m.selectedProject, m.selectedEnv) | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| return envDetailsFetchedMsg{ | ||
| sdkKey: keys.SDKKey, | ||
| clientSideID: keys.ClientSideID, | ||
| mobileKey: keys.MobileKey, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (m wizardModel) runDetect() tea.Cmd { | ||
| return func() tea.Msg { | ||
| dir, err := os.Getwd() | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| result, err := m.svc.Detect(dir) | ||
| if err != nil { | ||
| return detectFailedMsg{} | ||
| } | ||
| return detectDoneMsg{result: result} | ||
| } | ||
| } | ||
|
|
||
| func (m wizardModel) runInstall() tea.Cmd { | ||
| return func() tea.Msg { | ||
| dir, err := os.Getwd() | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| result, err := m.svc.Install(dir, m.detectResult) | ||
| if err != nil { | ||
| // Don't dead-end the interactive flow on a failed auto-install (e.g. | ||
| // Ruby gem perms, no network): surface the command to run by hand. | ||
| args, _ := setup.InstallArgs(m.detectResult.SDKID, m.detectResult.PackageManager) | ||
| return installDoneMsg{result: &setup.InstallResult{ | ||
| SDKID: m.detectResult.SDKID, | ||
| Command: strings.Join(args, " "), | ||
| Failed: true, | ||
| FailureReason: err.Error(), | ||
| }} | ||
| } | ||
| return installDoneMsg{result: result} | ||
| } | ||
| } | ||
|
|
||
| func (m wizardModel) runCreateFlag() tea.Cmd { | ||
| return func() tea.Msg { | ||
| key, err := m.svc.CreateFlag(m.auth, m.selectedProject, "my-new-flag", "My New Flag") | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| return flagCreatedMsg{key: key} | ||
| } | ||
| } | ||
|
|
||
| func (m wizardModel) runInit() tea.Cmd { | ||
| return func() tea.Msg { | ||
| cfg := setup.InitConfig{ | ||
| SDKKey: m.sdkKey, | ||
| ClientSideID: m.clientSideID, | ||
| MobileKey: m.mobileKey, | ||
| FlagKey: m.flagKey, | ||
| } | ||
| result, err := m.svc.Inject(m.detectResult.SDKID, m.detectResult.EntryPoint, cfg) | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| return initDoneMsg{result: result} | ||
| } | ||
| } | ||
|
|
||
| func (m wizardModel) runVerify() tea.Cmd { | ||
| return func() tea.Msg { | ||
| result, err := m.svc.Verify(m.auth, m.selectedProject, m.selectedEnv, m.detectResult.SDKID) | ||
| if err != nil { | ||
| return wizardErrMsg{err: err} | ||
| } | ||
| return verifyDoneMsg{result: result} | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package setup | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/launchdarkly/ldcli/cmd/cliflags" | ||
| "github.com/launchdarkly/ldcli/internal/setup" | ||
| ) | ||
|
|
||
| const pathFlag = "path" | ||
|
|
||
| func newDetectCmd(svc setup.Service) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "detect", | ||
| Short: "Detect language, framework, and recommended SDK for a project", | ||
| Hidden: true, | ||
| RunE: runDetect(svc), | ||
| } | ||
|
|
||
| cmd.Flags().String(pathFlag, "", "Path to the project directory (defaults to current directory)") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runDetect(svc setup.Service) func(*cobra.Command, []string) error { | ||
| return func(cmd *cobra.Command, args []string) error { | ||
| dir, _ := cmd.Flags().GetString(pathFlag) | ||
| if dir == "" { | ||
| var err error | ||
| dir, err = os.Getwd() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| result, err := svc.Detect(dir) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| outputKind := cliflags.GetOutputKind(cmd) | ||
| if outputKind == "json" { | ||
| data, _ := json.Marshal(result) | ||
| fmt.Fprintln(cmd.OutOrStdout(), string(data)) | ||
| return nil | ||
| } | ||
|
|
||
| fmt.Fprintf(cmd.OutOrStdout(), "Language: %s\n", result.Language) | ||
| if result.Framework != "" { | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Framework: %s\n", result.Framework) | ||
| } | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Package Manager: %s\n", result.PackageManager) | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Recommended SDK: %s\n", result.SDKID) | ||
| if result.EntryPointExists { | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Entry Point: %s\n", result.EntryPoint) | ||
| } else { | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Entry Point: %s (suggested, does not exist)\n", result.EntryPoint) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.