forked from hwaf/hwaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_pkg_ls.go
67 lines (55 loc) · 1.27 KB
/
cmd_pkg_ls.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
package main
import (
"fmt"
"regexp"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
)
func hwaf_make_cmd_pkg_ls() *commander.Command {
cmd := &commander.Command{
Run: hwaf_run_cmd_pkg_ls,
UsageLine: "ls [options] [pattern]",
Short: "list locally checked out packages",
Long: `
ls lists the locally checked out packages.
ex:
$ hwaf pkg ls
$ hwaf pkg ls ".*?Athena.*?"
`,
Flag: *flag.NewFlagSet("hwaf-pkg-ls", flag.ExitOnError),
}
cmd.Flag.Bool("v", false, "enable verbose output")
return cmd
}
func hwaf_run_cmd_pkg_ls(cmd *commander.Command, args []string) {
var err error
n := "hwaf-pkg-" + cmd.Name()
pat := ".*?"
switch len(args) {
case 0:
pat = ".*?"
case 1:
pat = args[0]
default:
err = fmt.Errorf("%s: you need to give a package pattern to list", n)
handle_err(err)
}
verbose := cmd.Flag.Lookup("v").Value.Get().(bool)
if verbose {
fmt.Printf("%s: listing packages [%s]...\n", n, pat)
}
re_pkg, err := regexp.Compile(pat)
handle_err(err)
pkgs := g_ctx.PkgDb.Pkgs()
for _, v := range pkgs {
if re_pkg.MatchString(v) {
pkg, err := g_ctx.PkgDb.GetPkg(v)
handle_err(err)
fmt.Printf("%s (%s)\n", pkg.Path, pkg.Type)
}
}
if verbose {
fmt.Printf("%s: listing packages [%s]... [ok]\n", n, pat)
}
}
// EOF