Skip to content

Commit ad36511

Browse files
committed
fix: refactor
1 parent 1c9326d commit ad36511

File tree

7 files changed

+457
-338
lines changed

7 files changed

+457
-338
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Compiled Go binaries
22
# Replace 'bootstrapper' with your actual executable name
33
bootstrap
4-
c.out
4+
coverage.out
55

66
# Project folders generated by your tool
77
# This pattern will ignore any folders starting with "new_project"

cmd/apply.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
7+
"github.com/spf13/cobra"
8+
"github.com/upsaurav12/bootstrap/pkg/parser"
9+
)
10+
11+
var applyCmd = cobra.Command{
12+
Use: "apply",
13+
Short: "Apply project configuration from YAML",
14+
Run: func(cmd *cobra.Command, args []string) {
15+
16+
if yamlPath == "" {
17+
fmt.Fprintln(cmd.OutOrStdout(), "Error: --yaml is required")
18+
return
19+
}
20+
21+
yamlConfig, err := parser.ReadYAML(yamlPath)
22+
if err != nil {
23+
fmt.Fprintln(cmd.OutOrStdout(), "error reading yaml:", err)
24+
return
25+
}
26+
27+
YAMLPath = yamlPath
28+
projectRouter = yamlConfig.Project.Router
29+
projectPort = strconv.Itoa(yamlConfig.Project.Port)
30+
DBType = yamlConfig.Project.Database
31+
Entities = yamlConfig.Entities
32+
33+
createNewProject(
34+
yamlConfig.Project.Name,
35+
projectRouter,
36+
yamlConfig.Project.Type,
37+
cmd.OutOrStdout(),
38+
)
39+
},
40+
}
41+
42+
var yamlPath string
43+
44+
type Config struct {
45+
Project Project `yaml:"project"`
46+
Entities []string `yaml:"entities"`
47+
CustomLogic []string `yaml:"custom_logic"`
48+
}
49+
50+
type Project struct {
51+
Name string `yaml:"name"`
52+
Type string `yaml:"type"`
53+
Port int `yaml:"port"`
54+
Location string `yaml:"location"`
55+
Database string `yaml:"db"`
56+
Router string `yaml:"router"`
57+
}
58+
59+
func init() {
60+
61+
applyCmd.Flags().StringVar(&yamlPath, "yaml", "", "yaml configuation")
62+
rootCmd.AddCommand(&applyCmd)
63+
}

0 commit comments

Comments
 (0)