-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
45 lines (35 loc) · 1002 Bytes
/
setup.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
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"flag"
"fmt"
"os"
"os/exec"
)
type Setup struct {
Common
Overwrite bool
}
func (cmd *Setup) Name() string { return "setup" }
func (cmd *Setup) Parse(args []string) error {
set := flag.NewFlagSet(cmd.Name(), flag.ExitOnError)
set.BoolVar(&cmd.Overwrite, "overwrite", false, "overwrite existing and reclone everything")
return set.Parse(args)
}
func (cmd *Setup) Exec() {
if !cmd.Overwrite && Exists(cmd.Path("src")) {
fmt.Fprintf(os.Stderr, "src directory %v already setup", cmd.Path("src"))
os.Exit(1)
}
// _ = os.RemoveAll(cmd.Path("pkg"))
_ = os.RemoveAll(cmd.Path("bin"))
_ = os.RemoveAll(cmd.Path("src"))
repodir := cmd.RepoDir()
fmt.Fprintf(os.Stdout, "# Cloning repository\n")
git := exec.Command("git", "clone", cmd.Repo, repodir)
git.Stdout, git.Stderr = os.Stdout, os.Stderr
ErrFatal(git.Run(), "git clone failed")
cmd.VendorModules()
cmd.FlattenVendor()
}