|
| 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