diff --git a/cmd/src/lsif_upload.go b/cmd/src/lsif_upload.go index 1a292f1ce3..daf34b2280 100644 --- a/cmd/src/lsif_upload.go +++ b/cmd/src/lsif_upload.go @@ -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: @@ -91,7 +101,7 @@ Examples: } fmt.Println("File: " + *fileFlag) - if rootFlag == nil { + if !isFlagSet(flagSet, "root") { checkError := func(err error) { if err != nil { fmt.Println(err) @@ -110,7 +120,8 @@ 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) @@ -118,7 +129,7 @@ Examples: fmt.Println("-root is outside the repository: " + *rootFlag) os.Exit(1) } - if *rootFlag == "." { + if *rootFlag == "." || *rootFlag == "/" { *rootFlag = "" } fmt.Println("Root: " + *rootFlag)