Skip to content

Commit

Permalink
Ensure we infer the LSIF upload root when no value is supplied. (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
efritz authored Mar 2, 2020
1 parent 67429fd commit 37ba97f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/src/lsif_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ import (
"github.com/mattn/go-isatty"
)

func isFlagSet(fs *flag.FlagSet, name string) bool {
var found bool
fs.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}

func init() {
usage := `
Examples:
Expand Down Expand Up @@ -96,7 +106,7 @@ Examples:
}
fmt.Println("File: " + *fileFlag)

if rootFlag == nil {
if !isFlagSet(flagSet, "root") {
checkError := func(err error) {
if err != nil {
fmt.Println(err)
Expand All @@ -115,15 +125,16 @@ Examples:
rel, err := filepath.Rel(strings.TrimSpace(string(topLevel)), absFile)
checkError(err)

*rootFlag = filepath.Dir(rel)
relDir := filepath.Dir(rel)
rootFlag = &relDir
}

*rootFlag = filepath.Clean(*rootFlag)
if strings.HasPrefix(*rootFlag, "..") {
fmt.Println("-root is outside the repository: " + *rootFlag)
os.Exit(1)
}
if *rootFlag == "." {
if *rootFlag == "." || *rootFlag == "/" {
*rootFlag = ""
}
fmt.Println("Root: " + *rootFlag)
Expand Down

0 comments on commit 37ba97f

Please sign in to comment.