/
check.go
56 lines (52 loc) · 1.33 KB
/
check.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
46
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"fmt"
"github.com/metrumresearchgroup/pxr/internal/R"
"github.com/metrumresearchgroup/rcmd"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/sync/semaphore"
"io/ioutil"
"path/filepath"
)
// checkCmd represents the R CMD check command
var checkCmd = &cobra.Command{
Use: "check",
Short: "run R CMD check with the cli, in parallel",
Long: `
run R CMD check on package(s) in parallel.
`,
RunE: rCheck,
}
func rCheck(cmd *cobra.Command, args []string) error {
sem := semaphore.NewWeighted(int64(cfg.Threads))
run(globalCtx, sem, args, func(path string, rs rcmd.RSettings) {
rs.EnvVars = rcmd.NvpAppend(rs.EnvVars, "BABYLON_EXE_PATH", "bbi")
baseName := filepath.Base(rs.LibPaths[0])
tdir, err := ioutil.TempDir("", fmt.Sprintf("*-check-%s", baseName))
if err != nil {
log.Fatal("error with temp dir: ", err)
}
log.Info(fmt.Sprintf("%s checking in directory: %s", baseName, tdir))
cleanup := R.NewDefaultCleanUp()
if cfg.NoCleanup {
cleanup.OnSuccess = false
cleanup.OnFailure = false
}
if err := R.Check(globalCtx,
path,
tdir,
cfg,
rcmd.CheckArgs{Output: tdir},
rs,
*rcmd.NewRunConfig(rcmd.WithPrefix(fmt.Sprintf("[%s] ", baseName))),
cleanup,
); err != nil {
log.Error(err)
}
})
return nil
}
func init() {
rootCmd.AddCommand(checkCmd)
}