Skip to content

Commit

Permalink
fix(cli): generate
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 committed Jan 26, 2025
1 parent 253ab33 commit e688be8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cli/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"

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

g := h24w17.NewGenerator(plan, schema)
planContent, err := readFile(plan)
if err != nil {
return fmt.Errorf("error reading plan file: %v", err)
}
schemaContent, err := readFile(schema)
if err != nil {
return fmt.Errorf("error reading schema file: %v", err)
}

g := h24w17.NewGenerator(planContent, schemaContent)
g.Generate(distPath)

return nil
Expand All @@ -35,3 +45,11 @@ func init() {
generateCmd.Flags().StringP("schema", "s", "schema.sql", "File containing the table schema")
rootCmd.AddCommand(generateCmd)
}

func readFile(path string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", fmt.Errorf("error reading file: %v", err)
}
return string(data), nil
}

0 comments on commit e688be8

Please sign in to comment.