-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconstants.go
More file actions
51 lines (47 loc) · 1.05 KB
/
constants.go
File metadata and controls
51 lines (47 loc) · 1.05 KB
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
44
45
46
47
48
49
50
51
package cmd
import (
"errors"
"fmt"
"github.com/spf13/cobra"
)
var (
constantsCmd = &cobra.Command{
Use: "constants",
Short: "Scan the directory trees and print out the constants declared",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
_ = cmd.Help()
return errors.New("too many arguments")
}
d, err := dep(true)
if err != nil {
return err
}
if d.CodeBase.Empty() {
fmt.Println("No SQL code found in given paths")
}
if d.CodeBase.HasErrors() {
fmt.Println("Errors:")
for _, e := range d.CodeBase.Errors() {
fmt.Printf("%s:%d:%d: %s\n", e.Pos.File, e.Pos.Line, e.Pos.Line, e.Message)
}
return nil
}
fmt.Println("declare")
for i, c := range d.CodeBase.Declares() {
var prefix string
if i == 0 {
prefix = " "
} else {
prefix = " , "
}
fmt.Printf("%s%s %s = %s\n", prefix, c.VariableName, c.Datatype.String(), c.Literal.RawValue)
}
fmt.Println(";")
return nil
},
}
)
func init() {
rootCmd.AddCommand(constantsCmd)
}