-
Notifications
You must be signed in to change notification settings - Fork 14
[REL-14909] Revive CLI Quickstart Wizard — integrate #708 + #709 #744
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
Closed
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f394728
REL-000: skeleton for the CLI
ari-launchdarkly b490e4e
make the suggested changes
ari-launchdarkly 0405325
make the suggested bugbot changes
ari-launchdarkly bfdfe48
address more bugbot comments
ari-launchdarkly 9bad6ba
make the suggested changes
ari-launchdarkly c0f9fec
[REL-13574] sdk detection and installation
dakotasanchez 0671b01
Update internal/setup/detector.go
dakotasanchez 5cacdae
Update internal/setup/detector.go
dakotasanchez 11088f2
Update internal/setup/installer.go
dakotasanchez 2498bbb
Update internal/setup/installer.go
dakotasanchez 3593f84
[REL-13574] feedback
dakotasanchez ce86df7
[REL-13574] change to always show (prioritized) SDK selector
dakotasanchez a344e11
[REL-13574] lingering bugs
dakotasanchez f243727
[REL-13574] merge resolution and new go code injection
dakotasanchez e33be9f
[REL-13574] fix panic and flag link
dakotasanchez 96a454c
Fix setup wizard review findings: init placement, ruby detect, dry-run
ffantl-ld 341b524
setup: pre-flight auth check with login guidance
ffantl-ld 9e81930
setup: friendlier not-logged-in copy and detected-SDK prompt
ffantl-ld 537b813
setup: dim the transition notice and separate it from output
ffantl-ld 58b888b
setup: split SDK selection into detected panel and other-SDKs list
ffantl-ld f0e7950
setup: show "Press q to quit" on the final screens
ffantl-ld ab2b416
setup: point to the detected SDK when its panel is focused
ffantl-ld f0a7c2b
setup: align SDK boxes and dim the unfocused list selection
ffantl-ld 71f5b9b
setup: skip install when the SDK is already a dependency
ffantl-ld 25ae37e
setup: preview the steps and confirm before running them
ffantl-ld 05d70c0
setup: clean up the not-logged-in message
ffantl-ld cf5bba8
setup: centralize TUI styles into shared tokens
ffantl-ld 183831b
setup: match the SDK list title style to the panel header
ffantl-ld e5fbed4
setup: go back to a previous selection with the left arrow
ffantl-ld a19b1c1
setup: detect the project once at launch and cache it
ffantl-ld b56b103
setup: single key hint in the SDK box and vim `h` for back
ffantl-ld 404be45
setup: graceful install fallback, manual-SDK marking, catalog link, w…
ffantl-ld 7abe7ed
setup: render init snippets and commands as code blocks
ffantl-ld 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 | ||
| } | ||
| } |
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,54 @@ | ||
| package setup | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
|
|
||
| cmdAnalytics "github.com/launchdarkly/ldcli/cmd/analytics" | ||
| "github.com/launchdarkly/ldcli/cmd/cliflags" | ||
| "github.com/launchdarkly/ldcli/internal/analytics" | ||
| "github.com/launchdarkly/ldcli/internal/flags" | ||
| "github.com/launchdarkly/ldcli/internal/resources" | ||
| "github.com/launchdarkly/ldcli/internal/setup" | ||
| ) | ||
|
|
||
| // NewSetupCmd creates the top-level setup command and registers its hidden subcommands. | ||
| func NewSetupCmd( | ||
| analyticsTrackerFn analytics.TrackerFn, | ||
| resourcesClient resources.Client, | ||
| flagsClient flags.Client, | ||
| detector setup.Detector, | ||
| installer setup.Installer, | ||
| ) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "setup", | ||
| Short: "Set up LaunchDarkly in your project", | ||
| Long: `Guided setup to integrate LaunchDarkly into your codebase. | ||
|
|
||
| Detects your project's language and framework, installs the correct SDK, | ||
| initializes it with your environment's SDK key, creates a feature flag, | ||
| and verifies the connection.`, | ||
| PreRun: func(cmd *cobra.Command, args []string) { | ||
| // Dim the notice and set it off with a blank line so it reads as a | ||
| // transitional notice, visually distinct from command output. | ||
| notice := mutedStyle.Render( | ||
| "Notice: 'ldcli setup' now runs the new guided setup wizard (project detection, SDK installation, and initialization).\n" + | ||
| "The previous quickstart wizard is still available via 'ldcli quickstart' during the transition period.") | ||
| fmt.Fprintf(cmd.ErrOrStderr(), "%s\n\n", notice) | ||
| analyticsTrackerFn( | ||
| viper.GetString(cliflags.AccessTokenFlag), | ||
| viper.GetString(cliflags.BaseURIFlag), | ||
| viper.GetBool(cliflags.AnalyticsOptOut), | ||
| ).SendCommandRunEvent(cmdAnalytics.CmdRunEventProperties(cmd, "setup", nil)) | ||
| }, | ||
| RunE: runSetupWizard(analyticsTrackerFn, resourcesClient, flagsClient, detector, installer), | ||
| } | ||
|
|
||
| cmd.AddCommand(newDetectCmd(detector)) | ||
| cmd.AddCommand(newInstallCmd(installer)) | ||
| cmd.AddCommand(newInitCmd()) | ||
|
|
||
| return cmd | ||
| } |
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.
Shared behavior change for 6 commands, not just
setup. The old code setDisableFlagParsing = trueforcompletion/config/help/login/signup/whoami; this replaces that with only clearing the--access-tokenrequired annotation. Cleaner intent, but not equivalent: any of those commands that relied on flag parsing being disabled — or had other required flags previously skipped — now behave differently.completionin particular passes args through.Please run
go test ./cmd/...on the rebased tree and smokeldcli completion bash,ldcli config,ldcli whoamibefore un-drafting. This is the only change reaching outsidesetup/.via LD Research 🤖