-
Notifications
You must be signed in to change notification settings - Fork 121
feat: add CLI command to get and update organizations #3763
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
Merged
forestileao
merged 13 commits into
superplanehq:main
from
Vukotije:feat/cli-organisation-get-update
Mar 30, 2026
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
68a6a5b
feat: add CLI command to get and update organizations
Vukotije 1a8a4ac
refactor: move resolveOrganizationID function to core package
Vukotije 94c0246
Merge branch 'main' into feat/cli-organisation-get-update
Vukotije 27bfd23
Merge branch 'main' into feat/cli-organisation-get-update
forestileao 04b7d6c
Merge branch 'main' into feat/cli-organisation-get-update
forestileao 2e95625
Merge branch 'main' into feat/cli-organisation-get-update
forestileao c73fca1
Merge branch 'main' into feat/cli-organisation-get-update
forestileao f89158f
Merge branch 'main' into feat/cli-organisation-get-update
Vukotije 375dcd5
Merge branch 'main' into feat/cli-organisation-get-update
forestileao a62a884
Merge branch 'main' into feat/cli-organisation-get-update
forestileao d1373b3
fix: remove unused import
Vukotije fb4fdaa
Merge branch 'main' into feat/cli-organisation-get-update
Vukotije d271a7a
Merge branch 'main' into feat/cli-organisation-get-update
Vukotije 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package organizations | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/superplanehq/superplane/pkg/cli/core" | ||
| "github.com/superplanehq/superplane/pkg/openapi_client" | ||
| ) | ||
|
|
||
| func resolveOrganizationID(ctx core.CommandContext) (string, error) { | ||
| me, _, err := ctx.API.MeAPI.MeMe(ctx.Context).Execute() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| if !me.HasOrganizationId() || strings.TrimSpace(me.GetOrganizationId()) == "" { | ||
| return "", fmt.Errorf("organization id not found for authenticated user") | ||
| } | ||
|
|
||
| return me.GetOrganizationId(), nil | ||
| } | ||
|
|
||
| func renderOrganization(stdout io.Writer, org openapi_client.OrganizationsOrganization) error { | ||
| metadata := org.GetMetadata() | ||
|
|
||
| _, _ = fmt.Fprintf(stdout, "ID: %s\n", metadata.GetId()) | ||
| _, _ = fmt.Fprintf(stdout, "Name: %s\n", metadata.GetName()) | ||
| _, _ = fmt.Fprintf(stdout, "Description: %s\n", metadata.GetDescription()) | ||
| _, _ = fmt.Fprintf(stdout, "Versioning Enabled: %t\n", metadata.GetVersioningEnabled()) | ||
| if metadata.HasCreatedAt() { | ||
| _, _ = fmt.Fprintf(stdout, "Created At: %s\n", metadata.GetCreatedAt().Format(time.RFC3339)) | ||
| } | ||
| if metadata.HasUpdatedAt() { | ||
| _, _ = fmt.Fprintf(stdout, "Updated At: %s\n", metadata.GetUpdatedAt().Format(time.RFC3339)) | ||
| } | ||
|
|
||
| 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,32 @@ | ||
| package organizations | ||
|
|
||
| import ( | ||
| "io" | ||
|
|
||
| "github.com/superplanehq/superplane/pkg/cli/core" | ||
| ) | ||
|
|
||
| type getCommand struct{} | ||
|
|
||
| func (c *getCommand) Execute(ctx core.CommandContext) error { | ||
| organizationID, err := resolveOrganizationID(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| response, _, err := ctx.API.OrganizationAPI. | ||
| OrganizationsDescribeOrganization(ctx.Context, organizationID). | ||
| Execute() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !ctx.Renderer.IsText() { | ||
| return ctx.Renderer.Render(response) | ||
| } | ||
|
|
||
| org := response.GetOrganization() | ||
| return ctx.Renderer.RenderText(func(stdout io.Writer) error { | ||
| return renderOrganization(stdout, org) | ||
| }) | ||
| } |
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,43 @@ | ||
| package organizations | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| "github.com/superplanehq/superplane/pkg/cli/core" | ||
| ) | ||
|
|
||
| func NewCommand(options core.BindOptions) *cobra.Command { | ||
| root := &cobra.Command{ | ||
| Use: "organizations", | ||
| Short: "Manage organizations", | ||
| Aliases: []string{"org", "orgs"}, | ||
| } | ||
|
|
||
| getCmd := &cobra.Command{ | ||
| Use: "get", | ||
| Short: "Get details for the current organization", | ||
| Args: cobra.NoArgs, | ||
| } | ||
| core.Bind(getCmd, &getCommand{}, options) | ||
|
|
||
| var updateName string | ||
| var updateDescription string | ||
| var updateVersioningEnabled bool | ||
| updateCmd := &cobra.Command{ | ||
| Use: "update", | ||
| Short: "Update the current organization", | ||
| Args: cobra.NoArgs, | ||
| } | ||
| updateCmd.Flags().StringVar(&updateName, "name", "", "organization name") | ||
| updateCmd.Flags().StringVar(&updateDescription, "description", "", "organization description") | ||
| updateCmd.Flags().BoolVar(&updateVersioningEnabled, "versioning-enabled", false, "enable or disable global versioning") | ||
| core.Bind(updateCmd, &updateCommand{ | ||
| name: &updateName, | ||
| description: &updateDescription, | ||
| versioningEnabled: &updateVersioningEnabled, | ||
| }, options) | ||
|
|
||
| root.AddCommand(getCmd) | ||
| root.AddCommand(updateCmd) | ||
|
|
||
| return root | ||
| } |
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 organizations | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
|
|
||
| "github.com/superplanehq/superplane/pkg/cli/core" | ||
| "github.com/superplanehq/superplane/pkg/openapi_client" | ||
| ) | ||
|
|
||
| type updateCommand struct { | ||
| name *string | ||
| description *string | ||
| versioningEnabled *bool | ||
| } | ||
|
|
||
| func (c *updateCommand) Execute(ctx core.CommandContext) error { | ||
| if !ctx.Cmd.Flags().Changed("name") && | ||
| !ctx.Cmd.Flags().Changed("description") && | ||
| !ctx.Cmd.Flags().Changed("versioning-enabled") { | ||
| return fmt.Errorf("at least one flag must be provided: --name, --description, or --versioning-enabled") | ||
| } | ||
|
|
||
| organizationID, err := resolveOrganizationID(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| metadata := openapi_client.OrganizationsOrganizationMetadata{} | ||
| if ctx.Cmd.Flags().Changed("name") { | ||
| metadata.SetName(*c.name) | ||
| } | ||
| if ctx.Cmd.Flags().Changed("description") { | ||
| metadata.SetDescription(*c.description) | ||
| } | ||
| if ctx.Cmd.Flags().Changed("versioning-enabled") { | ||
| metadata.SetVersioningEnabled(*c.versioningEnabled) | ||
| } | ||
|
|
||
| org := openapi_client.OrganizationsOrganization{} | ||
| org.SetMetadata(metadata) | ||
|
|
||
| body := openapi_client.OrganizationsUpdateOrganizationBody{} | ||
| body.SetOrganization(org) | ||
|
|
||
| response, _, err := ctx.API.OrganizationAPI. | ||
| OrganizationsUpdateOrganization(ctx.Context, organizationID). | ||
| Body(body). | ||
| Execute() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !ctx.Renderer.IsText() { | ||
| return ctx.Renderer.Render(response) | ||
| } | ||
|
|
||
| updated := response.GetOrganization() | ||
| return ctx.Renderer.RenderText(func(stdout io.Writer) error { | ||
| return renderOrganization(stdout, updated) | ||
| }) | ||
| } |
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
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.