Skip to content

Commit b82eedb

Browse files
devin-ai-integration[bot]theFongcloin
authored
Add brev org create command (#257)
* Add brev org create command with set suggestion Co-Authored-By: Alec Fong <alecsanf@usc.edu> * Fix string formatting in org create output * Add org create command to housekeeping group --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Alec Fong <alecsanf@usc.edu> Co-authored-by: Colin McNaughton <cloin@users.noreply.github.com>
1 parent 925c3c6 commit b82eedb

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

pkg/cmd/org/create.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/brevdev/brev-cli/pkg/cmd/cmderrors"
8+
"github.com/brevdev/brev-cli/pkg/cmdcontext"
9+
breverrors "github.com/brevdev/brev-cli/pkg/errors"
10+
"github.com/brevdev/brev-cli/pkg/store"
11+
"github.com/brevdev/brev-cli/pkg/terminal"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
func NewCmdOrgCreate(t *terminal.Terminal, orgcmdStore OrgCmdStore) *cobra.Command {
16+
cmd := &cobra.Command{
17+
Annotations: map[string]string{"housekeeping": ""},
18+
Use: "create",
19+
Short: "Create a new organization",
20+
Long: "Create a new organization with the specified name",
21+
Example: `
22+
brev org create my-new-org
23+
`,
24+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
25+
err := cmdcontext.InvokeParentPersistentPreRun(cmd, args)
26+
if err != nil {
27+
return breverrors.WrapAndTrace(err)
28+
}
29+
return nil
30+
},
31+
Args: cmderrors.TransformToValidationError(cobra.ExactArgs(1)),
32+
RunE: func(cmd *cobra.Command, args []string) error {
33+
err := createOrg(args[0], orgcmdStore, t)
34+
if err != nil {
35+
return breverrors.WrapAndTrace(err)
36+
}
37+
return nil
38+
},
39+
}
40+
return cmd
41+
}
42+
43+
func createOrg(orgName string, createStore OrgCmdStore, t *terminal.Terminal) error {
44+
if len(orgName) == 0 {
45+
return breverrors.NewValidationError("organization name cannot be empty")
46+
}
47+
48+
startTime := time.Now()
49+
50+
t.Vprintf("Creating organization %s...\n", t.Green(orgName))
51+
52+
org, err := createStore.CreateOrganization(store.CreateOrganizationRequest{
53+
Name: orgName,
54+
})
55+
if err != nil {
56+
return breverrors.WrapAndTrace(err)
57+
}
58+
59+
duration := time.Since(startTime)
60+
fmt.Print("\n")
61+
t.Vprint(t.Green(fmt.Sprintf("✓ Successfully created organization %s (ID: %s) in %v\n", org.Name, org.ID, duration.Round(time.Millisecond))))
62+
fmt.Print("\n")
63+
t.Vprint(t.Yellow("Switch to this organization:\n"))
64+
t.Vprint(t.Yellow(fmt.Sprintf("\tbrev org set %s\n", org.Name)))
65+
66+
return nil
67+
}

pkg/cmd/org/org.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type OrgCmdStore interface {
3030
GetServerSockFile() string
3131
CreateInviteLink(organizationID string) (string, error)
3232
GetCurrentWorkspaceID() (string, error)
33+
CreateOrganization(req store.CreateOrganizationRequest) (*entity.Organization, error)
3334
}
3435

3536
func NewCmdOrg(t *terminal.Terminal, orgcmdStore OrgCmdStore, noorgcmdStore OrgCmdStore) *cobra.Command {
@@ -64,6 +65,7 @@ func NewCmdOrg(t *terminal.Terminal, orgcmdStore OrgCmdStore, noorgcmdStore OrgC
6465

6566
cmd.AddCommand(NewCmdOrgSet(t, orgcmdStore, noorgcmdStore))
6667
cmd.AddCommand(NewCmdOrgLs(t, orgcmdStore))
68+
cmd.AddCommand(NewCmdOrgCreate(t, orgcmdStore))
6769
cmd.AddCommand(invite.NewCmdInvite(t, orgcmdStore, noorgcmdStore))
6870

6971
return cmd

0 commit comments

Comments
 (0)