Skip to content

Commit e7ef3e5

Browse files
authored
fix: remove flags in lang/golang/parser (cloudwego#22)
1 parent 2d1c9cd commit e7ef3e5

File tree

2 files changed

+1
-90
lines changed

2 files changed

+1
-90
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.23.0
44

55
require (
66
github.com/Knetic/govaluate v3.0.0+incompatible
7-
github.com/davecgh/go-spew v1.1.1
87
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd
98
github.com/sourcegraph/jsonrpc2 v0.2.0
109
github.com/stretchr/testify v1.10.0
@@ -13,6 +12,7 @@ require (
1312
)
1413

1514
require (
15+
github.com/davecgh/go-spew v1.1.1 // indirect
1616
github.com/pmezard/go-difflib v1.0.0 // indirect
1717
golang.org/x/sync v0.13.0 // indirect
1818
gopkg.in/yaml.v3 v3.0.1 // indirect

lang/golang/parser/go_ast.go

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -15,100 +15,11 @@
1515
package parser
1616

1717
import (
18-
"bytes"
19-
"encoding/json"
20-
"flag"
2118
"fmt"
22-
"os"
23-
"strings"
2419

2520
. "github.com/cloudwego/abcoder/lang/uniast"
2621
)
2722

28-
var (
29-
referCodeDepth int
30-
collectComment bool
31-
excludes string
32-
)
33-
34-
func init() {
35-
// init args with flags
36-
flag.Usage = func() {
37-
fmt.Fprintf(os.Stderr, "Usage: %s [options] <RepoDir> [id]\n", os.Args[0])
38-
flag.PrintDefaults()
39-
}
40-
flag.BoolVar(&collectComment, "collect_comment", false, "collect comments for each node")
41-
flag.IntVar(&referCodeDepth, "refer_code_depth", 0, "the depth to referenced codes, 0 means only return its identity")
42-
flag.StringVar(&excludes, "excludes", "", "exclude paths, seperated by comma")
43-
}
44-
45-
func Main() {
46-
var err error
47-
defer func() {
48-
if err != nil {
49-
fmt.Fprintln(os.Stderr, err.Error())
50-
}
51-
}()
52-
flag.Parse()
53-
as := flag.Args()
54-
if len(as) < 1 {
55-
flag.Usage()
56-
os.Exit(1)
57-
}
58-
59-
homeDir := as[0]
60-
id := ""
61-
if len(as) >= 2 {
62-
id = as[1]
63-
}
64-
65-
var exs []string
66-
if excludes != "" {
67-
exs = strings.Split(excludes, ",")
68-
}
69-
// p := NewParser(homeDir, homeDir, WithReferCodeDepth(referCodeDepth), WithExcludes(exs), WithCollectComment(collectComment))
70-
p := NewParser(homeDir, homeDir, Options{
71-
ReferCodeDepth: referCodeDepth,
72-
Excludes: exs,
73-
CollectComment: collectComment,
74-
})
75-
76-
var out interface{}
77-
78-
if id == "" {
79-
// parse whole repo
80-
if out, err = p.ParseRepo(); err != nil {
81-
return
82-
}
83-
} else {
84-
// SPEC: seperate the packagepath and entity name by #
85-
ids := strings.Split(id, "#")
86-
87-
if len(ids) == 1 {
88-
// parse pacakge
89-
pkgPath := ids[0]
90-
if out, err = p.ParsePackage(pkgPath); err != nil {
91-
return
92-
}
93-
} else if len(ids) == 2 {
94-
if out, err = p.ParseNode(ids[0], ids[1]); err != nil {
95-
return
96-
}
97-
}
98-
}
99-
100-
buf := bytes.NewBuffer(nil)
101-
encoder := json.NewEncoder(buf)
102-
encoder.SetEscapeHTML(false)
103-
err = encoder.Encode(out)
104-
if err != nil {
105-
fmt.Fprintln(os.Stderr, "Error marshalling functions to JSON:", err)
106-
os.Exit(1)
107-
}
108-
109-
fmt.Println(buf.String())
110-
}
111-
11223
func loadNode(p *GoParser, pkgPath string, name string, out *Repository) error {
11324
mod, _ := p.getModuleFromPkg(pkgPath)
11425
np, err := p.getNode(NewIdentity(mod, PkgPath(pkgPath), name))

0 commit comments

Comments
 (0)