-
Notifications
You must be signed in to change notification settings - Fork 4
/
commands.go
69 lines (56 loc) · 1.36 KB
/
commands.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
57
58
59
60
61
62
63
64
65
66
67
68
69
package commands
import (
"fmt"
"io"
"github.com/urfave/cli"
"jrubin.io/zb/cmd"
"jrubin.io/zb/lib/project"
"jrubin.io/zb/lib/zbcontext"
)
// Cmd is the commands command
var Cmd cmd.Constructor = &cc{}
type cc struct{}
func (co *cc) New(_ *cli.App) cli.Command {
return cli.Command{
Name: "commands",
Usage: "list all of the executables that will be emitted by the build command",
ArgsUsage: "[packages]",
Action: func(c *cli.Context) error {
ctx := cmd.Context(c)
ctx.ExcludeVendor = true
return co.run(ctx, c.App.Writer, c.Args()...)
},
}
}
func (co *cc) run(ctx zbcontext.Context, w io.Writer, args ...string) error {
if ctx.Package {
return co.commandsPackage(ctx, w, args...)
}
return co.commandsProject(ctx, w, args...)
}
func (co *cc) commandsPackage(ctx zbcontext.Context, w io.Writer, args ...string) error {
pkgs, err := project.ListPackages(ctx, args...)
if err != nil {
return err
}
for _, pkg := range pkgs {
if pkg.IsCommand() {
fmt.Fprintln(w, pkg.BuildPath(pkg.Dir))
}
}
return nil
}
func (co *cc) commandsProject(ctx zbcontext.Context, w io.Writer, args ...string) error {
projects, err := project.Projects(ctx, args...)
if err != nil {
return err
}
for _, p := range projects {
for _, pkg := range p.Packages {
if pkg.IsCommand() {
fmt.Fprintln(w, pkg.BuildPath(p.Dir))
}
}
}
return nil
}