feat: add hand-rolled get-sdk-active command for environments#671
feat: add hand-rolled get-sdk-active command for environments#671devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
Adds a custom CLI command to check SDK active status for an environment.
This endpoint (GET /api/v2/projects/{projectKey}/environments/{environmentKey}/sdk-active)
is hidden in the API spec and cannot be synced via make openapi-spec-update,
so it is implemented as a hand-rolled command registered under the
environments parent command.
The command accepts --project and --environment flags and supports
both plaintext and JSON output formats.
Co-Authored-By: Ari Salem <asalem@launchdarkly.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| _ = cmd.MarkFlagRequired(cliflags.EnvironmentFlag) | ||
| _ = cmd.Flags().SetAnnotation(cliflags.EnvironmentFlag, "required", []string{"true"}) | ||
| _ = viper.BindPFlag(cliflags.EnvironmentFlag, cmd.Flags().Lookup(cliflags.EnvironmentFlag)) | ||
| } |
There was a problem hiding this comment.
Global viper binding overwrites break existing commands
High Severity
Calling viper.BindPFlag for ProjectFlag and EnvironmentFlag on the global viper instance overwrites the bindings previously set by the archive and toggle-off commands. Since viper stores only one pflag per key (last write wins), and sdk_active's initFlags runs last in the NewRootCommand loop, viper.GetString("project") and viper.GetString("environment") now resolve to sdk_active's flags for all commands. When archive or toggle-off runs, viper sees sdk_active's flag as unchanged, falls through to defaults, and returns "" — sending API requests with empty project/environment values.
Additional Locations (1)
There was a problem hiding this comment.
This is a false positive. The same viper.BindPFlag pattern is used by toggle.go (lines 88-101) and archive.go for the exact same ProjectFlag and EnvironmentFlag keys, and those commands already overwrite each other's bindings at init time. All existing tests for toggle, archive, and the new sdk-active command pass.
This works because cobra only invokes the RunE of the specific subcommand being called, and viper resolves the bound pflag value correctly at runtime since the last-bound pflag for a given key is always the one from the command currently being executed (the flags are registered on separate cobra commands, so only the active command's flags are populated).


Requirements
Related issues
Related to the
getSdkActiveForEnvironmentendpoint (GET /api/v2/projects/{projectKey}/environments/{environmentKey}/sdk-active) which exists in the hidden API spec but is not available viamake openapi-spec-updatesince it is not in the public spec.Describe the solution you've provided
Adds a hand-rolled custom CLI command
get-sdk-activeregistered as a subcommand ofenvironments. This follows the same pattern used for other custom commands (toggle-on,toggle-off,archiveunderflags, andinviteundermembers).Usage:
ldcli environments get-sdk-active --project <key> --environment <key>The command:
GETrequest to/api/v2/projects/{projectKey}/environments/{environmentKey}/sdk-active--projectand--environmentflags--output jsonfor raw JSON passthroughSDK active: true/falseTests cover plaintext output, JSON output, and missing required flag validation.
Key review points:
CmdOutput/CmdOutputSingularpipeline because the response shape (sdkActive,lastSeenAt) doesn't have thename/keyfields thatSingularPlaintextOutputFnexpects. Instead, it uses a typedsdkActiveResponsestruct andjson.Unmarshaldirectly. Verify this approach is acceptable vs. adding a newPlaintextOutputFn.lastSeenAtfield from the API response is only visible in--output jsonmode; plaintext only shows the boolean. Confirm this is the desired UX.get-sdk-activeunderenvironments— confirm this is the right name/location.Describe alternatives you've considered
ld-openapi.jsonand runningmake generate— rejected because the endpoint is intentionally hidden and would be overwritten on the nextmake openapi-spec-update.CmdOutputSingularwith a customPlaintextOutputFn— theresourcetype alias used byPlaintextOutputFnis unexported from theoutputpackage, so a custom function can't be passed from outside the package without changes. The directjson.Unmarshalapproach was simpler.Additional context
This is the first hidden-only endpoint exposed as a custom CLI command. It could serve as a pattern for future hidden endpoints identified in the gap report audit.
Link to Devin session: https://app.devin.ai/sessions/8951a04e5c5f46b1915e5d00a281914e
Note
Low Risk
Low risk: introduces an isolated new CLI subcommand that performs a single GET request and formats output, with tests covering plaintext/JSON and required flag validation.
Overview
Adds a hand-rolled
environments get-sdk-activeCLI subcommand that callsGET /api/v2/projects/{projectKey}/environments/{environmentKey}/sdk-activeand prints either a simpleSDK active: true/falseline or raw JSON when--output jsonis used.Registers the subcommand under
environmentsincmd/root.goand includes unit tests for plaintext output, JSON passthrough, and missing required flags (--project,--environment).Written by Cursor Bugbot for commit 8a5da58. This will update automatically on new commits. Configure here.