-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (43 loc) · 1.53 KB
/
main.go
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
// Program add_argument inserts a new argument into a function and all of it's callers
//
// Example:
// $ add_argument -arg="foo int" -pos=$GOPATH/src/github.com/tmc/srcutils/test/original/z.go:#20 github.com/tmc/srcutils/test/original
package main
import (
"flag"
"fmt"
"os"
)
type Options struct {
position string // position
argument string // argument to add
args []string // ssa FromArgs
write bool
skipExists bool // skip if specified name and type are already present
packageNameRe string // package name regexp
callgraphDepth int // depth up the callgraph to make modifications
}
var options Options
func init() {
flag.StringVar(&options.argument, "arg", "",
"argument to add to the specified function")
flag.StringVar(&options.position, "pos", "",
"Filename and byte offset or extent of a syntax element about which to "+
"query, e.g. foo.go:#123,#456, bar.go:#123.")
flag.BoolVar(&options.write, "w", false,
"write result to (source) file instead of stdout")
flag.BoolVar(&options.skipExists, "skip-exists", true,
"if an argument appears to exist already don't add it")
flag.StringVar(&options.packageNameRe, "package-regexp", "",
"regular expression that package names much match to be modified")
flag.IntVar(&options.callgraphDepth, "depth", -1,
"callgraph traversal limit (-1 for unlimited) ")
}
func main() {
flag.Parse()
options.args = flag.Args()
if err := commandAddArgument(options); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s.\n", err)
os.Exit(1)
}
}