@@ -32,6 +32,7 @@ func envsCmd() *cobra.Command {
32
32
watchBuildLogCommand (),
33
33
rebuildEnvCommand (),
34
34
createEnvCmd (),
35
+ createEnvFromRepoCmd (),
35
36
editEnvCmd (),
36
37
)
37
38
return cmd
@@ -184,7 +185,6 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
184
185
if multiOrgMember && org == "" {
185
186
return xerrors .New ("org is required for multi-org members" )
186
187
}
187
-
188
188
importedImg , err := findImg (ctx , client , findImgConf {
189
189
email : coder .Me ,
190
190
imgName : img ,
@@ -252,6 +252,65 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
252
252
return cmd
253
253
}
254
254
255
+ func createEnvFromRepoCmd () * cobra.Command {
256
+ var (
257
+ branch string
258
+ name string
259
+ follow bool
260
+ )
261
+
262
+ cmd := & cobra.Command {
263
+ Use : "create-from-repo [environment_name]" ,
264
+ Short : "create a new environment from a git repository." ,
265
+ Args : xcobra .ExactArgs (1 ),
266
+ Long : "Create a new Coder environment from a Git repository." ,
267
+ Hidden : true ,
268
+ Example : `# create a new environment from git repository template
269
+ coder envs create-from-repo github.com/cdr/m
270
+ coder envs create-from-repo github.com/cdr/m --branch envs-as-code` ,
271
+ RunE : func (cmd * cobra.Command , args []string ) error {
272
+ ctx := cmd .Context ()
273
+
274
+ client , err := newClient (ctx )
275
+ if err != nil {
276
+ return err
277
+ }
278
+
279
+ // ExactArgs(1) ensures our name value can't panic on an out of bounds.
280
+ createReq := & coder.Template {
281
+ RepositoryURL : args [0 ],
282
+ Branch : branch ,
283
+ Name : name ,
284
+ }
285
+
286
+ env , err := client .CreateEnvironment (ctx , coder.CreateEnvironmentRequest {
287
+ Template : createReq ,
288
+ })
289
+ if err != nil {
290
+ return xerrors .Errorf ("create environment: %w" , err )
291
+ }
292
+
293
+ if follow {
294
+ clog .LogSuccess ("creating environment..." )
295
+ if err := trailBuildLogs (ctx , client , env .ID ); err != nil {
296
+ return err
297
+ }
298
+ return nil
299
+ }
300
+
301
+ clog .LogSuccess ("creating environment..." ,
302
+ clog .BlankLine ,
303
+ clog .Tipf (`run "coder envs watch-build %s" to trail the build logs` , env .Name ),
304
+ )
305
+ return nil
306
+ },
307
+ }
308
+ cmd .Flags ().StringVarP (& branch , "branch" , "b" , "master" , "name of the branch to create the environment from." )
309
+ cmd .Flags ().StringVarP (& name , "name" , "n" , "coder.yaml" , "name of the config file." )
310
+ cmd .Flags ().BoolVar (& follow , "follow" , false , "follow buildlog after initiating rebuild" )
311
+ return cmd
312
+ }
313
+
255
314
func editEnvCmd () * cobra.Command {
256
315
var (
257
316
org string
0 commit comments