-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdep.go
More file actions
65 lines (60 loc) · 1.41 KB
/
dep.go
File metadata and controls
65 lines (60 loc) · 1.41 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/vippsas/sqlcode"
)
func dep(partialParseResults bool) (d sqlcode.Deployable, err error) {
d, err = sqlcode.Include(
sqlcode.Options{
IncludeTags: tags,
PartialParseResults: partialParseResults,
},
os.DirFS(directory),
)
return
}
var (
depCmd = &cobra.Command{
Use: "dep",
Short: "Scan the directory trees and report which files were discovered, their ordering and their dependencies",
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 {
fmt.Println("Error during parsing: " + err.Error())
fmt.Println("Treat results below with caution.")
fmt.Println()
err = nil
}
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)
}
}
for _, c := range d.CodeBase.Creates() {
fmt.Println(c.QuotedName.String() + ":")
if len(c.DependsOn) > 0 {
fmt.Println(" Uses:")
for _, u := range c.DependsOn {
fmt.Println(" " + u.String())
}
}
fmt.Println()
}
return nil
},
}
)
func init() {
rootCmd.AddCommand(depCmd)
}