This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
65 lines (53 loc) · 1.47 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package play
import (
"fmt"
"github.com/fioncat/gitzombie/cmd/app"
"github.com/fioncat/gitzombie/config"
"github.com/fioncat/gitzombie/core"
"github.com/spf13/cobra"
)
type CreateFlags struct {
Builder string
Template []string
}
var Create = app.Register(&app.Command[CreateFlags, app.Empty]{
Use: "play [-b builder] {play}",
Desc: "Create a playground",
Action: "Create",
Prepare: func(cmd *cobra.Command, flags *CreateFlags) {
cmd.Flags().StringVarP(&flags.Builder, "builder", "b", "", "builder name")
cmd.RegisterFlagCompletionFunc("builder", app.Comp(app.CompBuilder))
cmd.Flags().StringSliceVarP(&flags.Template, "template", "t", nil, "template to use")
cmd.RegisterFlagCompletionFunc("template", app.Comp(app.CompTemplate))
cmd.Args = cobra.ExactArgs(1)
cmd.ValidArgsFunction = app.Comp(compGroup)
},
Run: func(ctx *app.Context[CreateFlags, app.Empty]) error {
var err error
builder := core.DefaultBuilder
if ctx.Flags.Builder != "" {
builder, err = core.GetBuilder(ctx.Flags.Builder)
if err != nil {
return err
}
}
if len(ctx.Flags.Template) > 0 {
builder.Templates = append(builder.Templates, ctx.Flags.Template...)
}
rootDir := config.Get().Playground
repo, err := core.NewLocalRepository(rootDir, ctx.Arg(0))
if err != nil {
return err
}
err = builder.Prepare(nil, repo)
if err != nil {
return err
}
err = builder.Execute()
if err != nil {
return err
}
fmt.Println(repo.Path)
return nil
},
})