Skip to content

Commit e688be8

Browse files
committed
fix(cli): generate
1 parent 253ab33 commit e688be8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cli/generator.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/spf13/cobra"
78
h24w17 "github.com/traP-jp/h24w-17"
@@ -23,7 +24,16 @@ var generateCmd = &cobra.Command{
2324
}
2425
distPath := args[0]
2526

26-
g := h24w17.NewGenerator(plan, schema)
27+
planContent, err := readFile(plan)
28+
if err != nil {
29+
return fmt.Errorf("error reading plan file: %v", err)
30+
}
31+
schemaContent, err := readFile(schema)
32+
if err != nil {
33+
return fmt.Errorf("error reading schema file: %v", err)
34+
}
35+
36+
g := h24w17.NewGenerator(planContent, schemaContent)
2737
g.Generate(distPath)
2838

2939
return nil
@@ -35,3 +45,11 @@ func init() {
3545
generateCmd.Flags().StringP("schema", "s", "schema.sql", "File containing the table schema")
3646
rootCmd.AddCommand(generateCmd)
3747
}
48+
49+
func readFile(path string) (string, error) {
50+
data, err := os.ReadFile(path)
51+
if err != nil {
52+
return "", fmt.Errorf("error reading file: %v", err)
53+
}
54+
return string(data), nil
55+
}

0 commit comments

Comments
 (0)