-
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| 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(detector setup.Detector) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "detect", | ||
| Short: "Detect language, framework, and recommended SDK for a project", | ||
| Hidden: true, | ||
| RunE: runDetect(detector), | ||
| } | ||
|
|
||
| cmd.Flags().String(pathFlag, "", "Path to the project directory (defaults to current directory)") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runDetect(detector setup.Detector) 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 := detector.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) | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Entry Point: %s\n", result.EntryPoint) | ||
|
|
||
| return nil | ||
| } | ||
| } |
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,86 @@ | ||
| package setup | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/launchdarkly/ldcli/cmd/cliflags" | ||
| "github.com/launchdarkly/ldcli/internal/setup" | ||
| ) | ||
|
|
||
| func getFlag(cmd *cobra.Command, name string) string { | ||
| v, _ := cmd.Flags().GetString(name) | ||
| return v | ||
| } | ||
|
|
||
| const ( | ||
| fileFlag = "file" | ||
| sdkKeyFlag = "sdk-key" | ||
| clientIDFlag = "client-side-id" | ||
| mobileFlag = "mobile-key" | ||
| flagKeyFlag = "flag-key" | ||
| ) | ||
|
|
||
| func newInitCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "init", | ||
| Short: "Inject LaunchDarkly SDK initialization code into a file", | ||
| Hidden: true, | ||
| RunE: runInit(), | ||
| } | ||
|
|
||
| cmd.Flags().String(sdkIDFlag, "", "SDK identifier (e.g. node-server, react-client-sdk)") | ||
| _ = cmd.MarkFlagRequired(sdkIDFlag) | ||
|
|
||
| cmd.Flags().String(fileFlag, "", "Target file to inject initialization code into") | ||
| _ = cmd.MarkFlagRequired(fileFlag) | ||
|
|
||
| cmd.Flags().String(sdkKeyFlag, "", "Server-side SDK key") | ||
| cmd.Flags().String(clientIDFlag, "", "Client-side environment ID") | ||
| cmd.Flags().String(mobileFlag, "", "Mobile SDK key") | ||
| cmd.Flags().String(flagKeyFlag, "", "Feature flag key to use in the initialization example") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runInit() func(*cobra.Command, []string) error { | ||
| return func(cmd *cobra.Command, args []string) error { | ||
| sdkID, _ := cmd.Flags().GetString(sdkIDFlag) | ||
| filePath, _ := cmd.Flags().GetString(fileFlag) | ||
| cfg := setup.InitConfig{ | ||
| SDKKey: getFlag(cmd, sdkKeyFlag), | ||
| ClientSideID: getFlag(cmd, clientIDFlag), | ||
| MobileKey: getFlag(cmd, mobileFlag), | ||
| FlagKey: getFlag(cmd, flagKeyFlag), | ||
| } | ||
|
|
||
| initializer := setup.Initializer{} | ||
| result, err := initializer.InjectIntoFile(sdkID, filePath, cfg) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| outputKind := cliflags.GetOutputKind(cmd) | ||
| if outputKind == "json" { | ||
| data, _ := json.Marshal(result) | ||
| fmt.Fprintln(cmd.OutOrStdout(), string(data)) | ||
| return nil | ||
| } | ||
|
|
||
| if !result.Success { | ||
| if result.Snippet != "" { | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Manual setup required for %s — add the following to %s:\n\n%s\n\n", result.SDKID, result.FilePath, result.Snippet) | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Follow the setup guide at: %s\n", result.DocsURL) | ||
| return nil | ||
| } | ||
| fmt.Fprintf(cmd.OutOrStdout(), "No initialization template available for %s\n", result.SDKID) | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Follow the setup guide at: %s\n", result.DocsURL) | ||
| return nil | ||
| } | ||
|
|
||
| fmt.Fprintf(cmd.OutOrStdout(), "Injected %s initialization into %s\n", result.SDKID, result.FilePath) | ||
| return nil | ||
| } | ||
| } |
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,99 @@ | ||
| package setup | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/launchdarkly/ldcli/cmd/cliflags" | ||
| "github.com/launchdarkly/ldcli/internal/setup" | ||
| ) | ||
|
|
||
| const ( | ||
| sdkIDFlag = "sdk-id" | ||
| dryRunFlag = "dry-run" | ||
| ) | ||
|
|
||
| func newInstallCmd(installer setup.Installer) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "install", | ||
| Short: "Install the LaunchDarkly SDK package for the detected project", | ||
| Hidden: true, | ||
| RunE: runInstall(installer), | ||
| } | ||
|
|
||
| cmd.Flags().String(pathFlag, "", "Path to the project directory (defaults to current directory)") | ||
| cmd.Flags().String(sdkIDFlag, "", "SDK identifier to install (e.g. node-server, react-client-sdk)") | ||
| _ = cmd.MarkFlagRequired(sdkIDFlag) | ||
| cmd.Flags().String("package-manager", "", "Package manager to use (e.g. npm, pip, go)") | ||
| cmd.Flags().Bool(dryRunFlag, false, "Print the install command that would run without executing it") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runInstall(installer setup.Installer) 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 | ||
| } | ||
| } | ||
|
|
||
| sdkID, _ := cmd.Flags().GetString(sdkIDFlag) | ||
| pkgMgr, _ := cmd.Flags().GetString("package-manager") | ||
| dryRun, _ := cmd.Flags().GetBool(dryRunFlag) | ||
| detection := &setup.DetectResult{ | ||
| SDKID: sdkID, | ||
| PackageManager: pkgMgr, | ||
| } | ||
|
|
||
| var result *setup.InstallResult | ||
| if dryRun { | ||
| args, pkg := setup.InstallArgs(sdkID, pkgMgr) | ||
| result = &setup.InstallResult{ | ||
| SDKID: sdkID, | ||
| Package: pkg, | ||
| Command: strings.Join(args, " "), | ||
| DryRun: true, | ||
| } | ||
| } else { | ||
| var err error | ||
| result, err = installer.Install(dir, detection) | ||
| 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(), "SDK: %s\n", result.SDKID) | ||
| if result.Version != "" { | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Package: %s@%s\n", result.Package, result.Version) | ||
| } else { | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Package: %s\n", result.Package) | ||
| } | ||
| if result.AlreadyInstalled { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "Already installed — skipping install.") | ||
| return nil | ||
| } | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Command: %s\n", result.Command) | ||
| if result.DryRun { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "Dry run: command not executed") | ||
| } else { | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Success: %t\n", result.Success) | ||
| } | ||
|
|
||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbols command registration removed
High Severity
The
symbolscommand import andAddCommandwiring were dropped from the root command, and its help entry was removed from the usage template, whilecmd/symbolsstill exists and was recently shipped. Users can no longer runldcli symbols.Additional Locations (1)
cmd/templates.go#L28-L30Reviewed by Cursor Bugbot for commit 97c6a7d. Configure here.