Skip to content

Commit 37ba97f

Browse files
authored
Ensure we infer the LSIF upload root when no value is supplied. (#145)
1 parent 67429fd commit 37ba97f

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

cmd/src/lsif_upload.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ import (
2020
"github.com/mattn/go-isatty"
2121
)
2222

23+
func isFlagSet(fs *flag.FlagSet, name string) bool {
24+
var found bool
25+
fs.Visit(func(f *flag.Flag) {
26+
if f.Name == name {
27+
found = true
28+
}
29+
})
30+
return found
31+
}
32+
2333
func init() {
2434
usage := `
2535
Examples:
@@ -96,7 +106,7 @@ Examples:
96106
}
97107
fmt.Println("File: " + *fileFlag)
98108

99-
if rootFlag == nil {
109+
if !isFlagSet(flagSet, "root") {
100110
checkError := func(err error) {
101111
if err != nil {
102112
fmt.Println(err)
@@ -115,15 +125,16 @@ Examples:
115125
rel, err := filepath.Rel(strings.TrimSpace(string(topLevel)), absFile)
116126
checkError(err)
117127

118-
*rootFlag = filepath.Dir(rel)
128+
relDir := filepath.Dir(rel)
129+
rootFlag = &relDir
119130
}
120131

121132
*rootFlag = filepath.Clean(*rootFlag)
122133
if strings.HasPrefix(*rootFlag, "..") {
123134
fmt.Println("-root is outside the repository: " + *rootFlag)
124135
os.Exit(1)
125136
}
126-
if *rootFlag == "." {
137+
if *rootFlag == "." || *rootFlag == "/" {
127138
*rootFlag = ""
128139
}
129140
fmt.Println("Root: " + *rootFlag)

0 commit comments

Comments
 (0)