-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.go
More file actions
43 lines (37 loc) · 845 Bytes
/
build.go
File metadata and controls
43 lines (37 loc) · 845 Bytes
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
package cmd
import (
"errors"
"fmt"
mssql "github.com/microsoft/go-mssqldb"
"github.com/spf13/cobra"
"github.com/vippsas/sqlcode"
)
var (
buildCmd = &cobra.Command{
Use: "build schemasuffix",
Short: "Dump the SQL that will be executed to populate the [code] schema to stdout",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
_ = cmd.Help()
return errors.New("need to specify argument <schemasuffix>")
}
schemasuffix := args[0]
d, err := dep(false)
if err != nil {
return err
}
preprocessed, err := sqlcode.Preprocess(d.CodeBase, schemasuffix, &mssql.Driver{})
if err != nil {
return err
}
for _, p := range preprocessed.Batches {
fmt.Println(p.Lines)
fmt.Println("===")
}
return nil
},
}
)
func init() {
rootCmd.AddCommand(buildCmd)
}