-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.go
More file actions
52 lines (39 loc) · 916 Bytes
/
cmd.go
File metadata and controls
52 lines (39 loc) · 916 Bytes
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
package rcmd
import (
"context"
"os"
"runtime"
"github.com/metrumresearchgroup/command"
)
type RCmd struct {
*command.Cmd
Prefix string
UseLineNumbers bool
Script bool
RSettings *RSettings
}
func NewRScript(ctx context.Context, dir string, args ...string) (*RCmd, error) {
return newRCmd(ctx, true, dir, args...)
}
func newRCmd(ctx context.Context, script bool, dir string, args ...string) (*RCmd, error) {
rcmd := &RCmd{
Script: script,
}
rs, err := NewRSettings("")
if err != nil {
return nil, err
}
env, err := ConfigureEnv(os.Environ(), rs)
if err != nil {
return nil, err
}
rpath := rs.R(runtime.GOOS, rcmd.Script)
cmd := command.NewWithContext(ctx, rpath, args...)
cmd.Dir = dir
cmd.Env = env
rcmd.Cmd = cmd
return rcmd, nil
}
func New(ctx context.Context, dir string, args ...string) (*RCmd, error) {
return newRCmd(ctx, false, dir, args...)
}