@@ -6,19 +6,21 @@ import (
6
6
"os"
7
7
8
8
"github.com/go-errors/errors"
9
- "github.com/google/uuid"
10
9
"github.com/spf13/afero"
11
10
"github.com/spf13/cobra"
12
11
"github.com/supabase/cli/internal/branches/create"
13
12
"github.com/supabase/cli/internal/branches/delete"
14
13
"github.com/supabase/cli/internal/branches/disable"
15
14
"github.com/supabase/cli/internal/branches/get"
16
15
"github.com/supabase/cli/internal/branches/list"
16
+ "github.com/supabase/cli/internal/branches/pause"
17
+ "github.com/supabase/cli/internal/branches/unpause"
17
18
"github.com/supabase/cli/internal/branches/update"
18
19
"github.com/supabase/cli/internal/gen/keys"
19
20
"github.com/supabase/cli/internal/utils"
20
21
"github.com/supabase/cli/internal/utils/flags"
21
22
"github.com/supabase/cli/pkg/api"
23
+ "github.com/supabase/cli/pkg/cast"
22
24
)
23
25
24
26
var (
40
42
Long : "Create a preview branch for the linked project." ,
41
43
Args : cobra .MaximumNArgs (1 ),
42
44
RunE : func (cmd * cobra.Command , args []string ) error {
43
- var body api.CreateBranchBody
45
+ body := api.CreateBranchBody { IsDefault : cast . Ptr ( false )}
44
46
if len (args ) > 0 {
45
47
body .BranchName = args [0 ]
46
48
}
@@ -74,14 +76,16 @@ var (
74
76
branchId string
75
77
76
78
branchGetCmd = & cobra.Command {
77
- Use : "get [branch-id ]" ,
79
+ Use : "get [name ]" ,
78
80
Short : "Retrieve details of a preview branch" ,
79
81
Long : "Retrieve details of the specified preview branch." ,
80
82
Args : cobra .MaximumNArgs (1 ),
81
83
RunE : func (cmd * cobra.Command , args []string ) error {
82
84
ctx := cmd .Context ()
83
85
fsys := afero .NewOsFs ()
84
- if err := promptBranchId (ctx , args , fsys ); err != nil {
86
+ if len (args ) > 0 {
87
+ branchId = args [0 ]
88
+ } else if err := promptBranchId (ctx , fsys ); err != nil {
85
89
return err
86
90
}
87
91
return get .Run (ctx , branchId , fsys )
@@ -101,7 +105,7 @@ var (
101
105
gitBranch string
102
106
103
107
branchUpdateCmd = & cobra.Command {
104
- Use : "update [branch-id ]" ,
108
+ Use : "update [name ]" ,
105
109
Short : "Update a preview branch" ,
106
110
Long : "Update a preview branch by its name or ID." ,
107
111
Args : cobra .MaximumNArgs (1 ),
@@ -122,32 +126,69 @@ var (
122
126
}
123
127
ctx := cmd .Context ()
124
128
fsys := afero .NewOsFs ()
125
- if err := promptBranchId (ctx , args , fsys ); err != nil {
129
+ if len (args ) > 0 {
130
+ branchId = args [0 ]
131
+ } else if err := promptBranchId (ctx , fsys ); err != nil {
126
132
return err
127
133
}
128
134
return update .Run (cmd .Context (), branchId , body , fsys )
129
135
},
130
136
}
131
137
138
+ branchPauseCmd = & cobra.Command {
139
+ Use : "pause [name]" ,
140
+ Short : "Pause a preview branch" ,
141
+ Args : cobra .MaximumNArgs (1 ),
142
+ RunE : func (cmd * cobra.Command , args []string ) error {
143
+ ctx := cmd .Context ()
144
+ fsys := afero .NewOsFs ()
145
+ if len (args ) > 0 {
146
+ branchId = args [0 ]
147
+ } else if err := promptBranchId (ctx , fsys ); err != nil {
148
+ return err
149
+ }
150
+ return pause .Run (ctx , branchId )
151
+ },
152
+ }
153
+
154
+ branchUnpauseCmd = & cobra.Command {
155
+ Use : "unpause [name]" ,
156
+ Short : "Unpause a preview branch" ,
157
+ Args : cobra .MaximumNArgs (1 ),
158
+ RunE : func (cmd * cobra.Command , args []string ) error {
159
+ ctx := cmd .Context ()
160
+ fsys := afero .NewOsFs ()
161
+ if len (args ) > 0 {
162
+ branchId = args [0 ]
163
+ } else if err := promptBranchId (ctx , fsys ); err != nil {
164
+ return err
165
+ }
166
+ return unpause .Run (ctx , branchId )
167
+ },
168
+ }
169
+
132
170
branchDeleteCmd = & cobra.Command {
133
- Use : "delete [branch-id ]" ,
171
+ Use : "delete [name ]" ,
134
172
Short : "Delete a preview branch" ,
135
173
Long : "Delete a preview branch by its name or ID." ,
136
174
Args : cobra .MaximumNArgs (1 ),
137
175
RunE : func (cmd * cobra.Command , args []string ) error {
138
176
ctx := cmd .Context ()
139
177
fsys := afero .NewOsFs ()
140
- if err := promptBranchId (ctx , args , fsys ); err != nil {
178
+ if len (args ) > 0 {
179
+ branchId = args [0 ]
180
+ } else if err := promptBranchId (ctx , fsys ); err != nil {
141
181
return err
142
182
}
143
183
return delete .Run (ctx , branchId )
144
184
},
145
185
}
146
186
147
187
branchDisableCmd = & cobra.Command {
148
- Use : "disable" ,
149
- Short : "Disable preview branching" ,
150
- Long : "Disable preview branching for the linked project." ,
188
+ Hidden : true ,
189
+ Use : "disable" ,
190
+ Short : "Disable preview branching" ,
191
+ Long : "Disable preview branching for the linked project." ,
151
192
RunE : func (cmd * cobra.Command , args []string ) error {
152
193
return disable .Run (cmd .Context (), afero .NewOsFs ())
153
194
},
@@ -173,18 +214,13 @@ func init() {
173
214
branchesCmd .AddCommand (branchUpdateCmd )
174
215
branchesCmd .AddCommand (branchDeleteCmd )
175
216
branchesCmd .AddCommand (branchDisableCmd )
217
+ branchesCmd .AddCommand (branchPauseCmd )
218
+ branchesCmd .AddCommand (branchUnpauseCmd )
176
219
rootCmd .AddCommand (branchesCmd )
177
220
}
178
221
179
- func promptBranchId (ctx context.Context , args []string , fsys afero.Fs ) error {
180
- var filter []list.BranchFilter
181
- if len (args ) > 0 {
182
- if branchId = args [0 ]; uuid .Validate (branchId ) == nil {
183
- return nil
184
- }
185
- // Try resolving as branch name
186
- filter = append (filter , list .FilterByName (branchId ))
187
- } else if console := utils .NewConsole (); ! console .IsTTY {
222
+ func promptBranchId (ctx context.Context , fsys afero.Fs ) error {
223
+ if console := utils .NewConsole (); ! console .IsTTY {
188
224
// Only read from stdin if the terminal is non-interactive
189
225
title := "Enter the name of your branch"
190
226
if branchId = keys .GetGitBranch (fsys ); len (branchId ) > 0 {
@@ -199,16 +235,14 @@ func promptBranchId(ctx context.Context, args []string, fsys afero.Fs) error {
199
235
if len (branchId ) == 0 {
200
236
return errors .New ("branch name cannot be empty" )
201
237
}
202
- filter = append ( filter , list . FilterByName ( branchId ))
238
+ return nil
203
239
}
204
- branches , err := list .ListBranch (ctx , flags .ProjectRef , filter ... )
240
+ branches , err := list .ListBranch (ctx , flags .ProjectRef )
205
241
if err != nil {
206
242
return err
207
243
} else if len (branches ) == 0 {
208
- return errors .Errorf ("branch not found: %s" , branchId )
209
- } else if len (branches ) == 1 {
210
- branchId = branches [0 ].Id .String ()
211
- return nil
244
+ utils .CmdSuggestion = fmt .Sprintf ("Create your first branch with: %s" , utils .Aqua ("supabase branches create" ))
245
+ return errors .Errorf ("branching is disabled" )
212
246
}
213
247
// Let user choose from a list of branches
214
248
items := make ([]utils.PromptItem , len (branches ))
0 commit comments