forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
45 lines (39 loc) · 996 Bytes
/
doc.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
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/constabulary/gb"
"github.com/constabulary/gb/cmd"
)
func init() {
registerCommand(&cmd.Command{
Name: "doc",
UsageLine: `doc <pkg> <sym>[.<method>]`,
Short: "show documentation for a package or symbol",
Long: `
Doc shows documentation for a package or symbol.
See 'go help doc'.
`,
Run: func(ctx *gb.Context, args []string) error {
env := cmd.MergeEnv(os.Environ(), map[string]string{
"GOPATH": fmt.Sprintf("%s:%s", ctx.Projectdir(), filepath.Join(ctx.Projectdir(), "vendor")),
})
if len(args) == 0 {
args = append(args, ".")
}
args = append([]string{filepath.Join(ctx.Context.GOROOT, "bin", "godoc")}, args...)
cmd := exec.Cmd{
Path: args[0],
Args: args,
Env: env,
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
}
return cmd.Run()
},
ParseArgs: func(_ *gb.Context, _ string, args []string) []string { return args },
})
}