-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_make_controller.go
More file actions
79 lines (65 loc) · 1.86 KB
/
Copy pathcmd_make_controller.go
File metadata and controls
79 lines (65 loc) · 1.86 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"path/filepath"
"github.com/spf13/cobra"
)
var makeControllerNoAuth bool
var makeControllerCmd = &cobra.Command{
Use: "make:controller <Name>",
Short: "Scaffold a new fuego controller",
Long: bold(
"make:controller",
) + ` scaffolds a module controller in ` + colorCyan + `internal/modules/<domain>/controller.go` + colorReset + `.
The generated controller includes ` + colorCyan + `Mount` + colorReset + ` and ` + colorCyan + `Wire` + colorReset + ` methods
matching the modular MSC architecture. OpenAPI docs are scaffolded in ` + colorCyan + `docs.go` + colorReset + `.
Pass ` + colorGreen + `--no-auth` + colorReset + ` to generate legacy function-based handlers instead.
` + colorGray + `Examples:` + colorReset + `
grove make:controller Post
grove make:controller Post --no-auth`,
Args: cobra.ExactArgs(1),
RunE: runMakeController,
}
func init() {
makeControllerCmd.Flags().BoolVar(
&makeControllerNoAuth,
"no-auth",
false,
"Generate legacy function-based handlers instead of a struct controller",
)
}
func runMakeController(_ *cobra.Command, args []string) error {
name := toPascalCase(toSingular(args[0]))
modDir := moduleDir(name)
fmt.Println()
fmt.Printf(
" %sCreating controller%s %s\n",
colorGray, colorReset,
bold(name),
)
fmt.Println()
if err := scaffoldController(name, makeControllerNoAuth); err != nil {
return err
}
if !makeControllerNoAuth {
if err := scaffoldDocs(name); err != nil {
return err
}
}
fmt.Println()
fmt.Println(nextSteps())
fmt.Printf(
" %s1.%s Implement handlers in %s\n",
colorGray, colorReset,
colorCyan+filepath.Join(modDir, "controller.go")+colorReset,
)
if !makeControllerNoAuth {
fmt.Printf(
" %s2.%s Register the module in %s\n",
colorGray, colorReset,
colorCyan+"internal/modules/register.go"+colorReset,
)
}
fmt.Println()
return nil
}