Repository navigation
Expand file tree
/
Copy pathargs.go
More file actions
74 lines (61 loc) · 2.1 KB
/
Copy pathargs.go
File metadata and controls
74 lines (61 loc) · 2.1 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"errors"
"fmt"
"path/filepath"
"strings"
"github.com/alecthomas/kingpin"
"github.com/sourcegraph/lsif-go/internal/git"
"github.com/sourcegraph/lsif-go/protocol"
)
var app = kingpin.New(
"lsif-go",
"lsif-go is an LSIF indexer for Go.",
).Version(version + ", protocol version " + protocol.Version)
var (
outFile string
moduleVersion string
repositoryRoot string
moduleRoot string
projectRoot string
noProgress bool
noOutput bool
verboseOutput bool
)
func init() {
app.HelpFlag.Short('h')
app.VersionFlag.Short('v')
app.HelpFlag.Hidden()
app.Flag("out", "The output file.").Short('o').Default("dump.lsif").StringVar(&outFile)
app.Flag("moduleVersion", "Specifies the version of the module defined by this project.").PlaceHolder("version").StringVar(&moduleVersion)
app.Flag("repositoryRoot", "Specifies the path of the current repository (inferred automatically via git).").PlaceHolder("root").StringVar(&repositoryRoot)
app.Flag("moduleRoot", "Specifies the module root directory relative to the repository").Default(".").StringVar(&moduleRoot)
app.Flag("noProgress", "Do not output verbose progress.").Default("false").BoolVar(&noProgress)
app.Flag("noOutput", "Do not output progress.").Default("false").BoolVar(&noOutput)
app.Flag("verbose", "Display timings and stats.").Default("false").BoolVar(&verboseOutput)
}
func parseArgs(args []string) (err error) {
if _, err := app.Parse(args); err != nil {
return err
}
repositoryRoot, err = filepath.Abs(repositoryRoot)
if err != nil {
return fmt.Errorf("get abspath of repository root: %v", err)
}
if repositoryRoot == "" {
toplevel, err := git.TopLevel(repositoryRoot)
if err != nil {
return fmt.Errorf("get git root: %v", err)
}
repositoryRoot = strings.TrimSpace(string(toplevel))
}
projectRoot, err = filepath.Abs(moduleRoot)
if err != nil {
return fmt.Errorf("get abspath of project root: %v", err)
}
// Ensure the module root is inside the repository
if !strings.HasPrefix(projectRoot, repositoryRoot) {
return errors.New("module root is outside the repository")
}
return nil
}