forked from lhcb-org/lbpkr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_list.go
67 lines (57 loc) · 1.25 KB
/
cmd_list.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"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
)
func lbpkr_make_cmd_list() *commander.Command {
cmd := &commander.Command{
Run: lbpkr_run_cmd_list,
UsageLine: "list [options] <name-pattern> [<version-pattern> [<release-pattern>]]",
Short: "list RPM packages",
Long: `
list lists all RPM packages satisfying <name-pattern>.
ex:
$ lbpkr list GAUDI
$ lbpkr list GAUDI v23r2
`,
Flag: *flag.NewFlagSet("lbpkr-list", flag.ExitOnError),
}
add_default_options(cmd)
return cmd
}
func lbpkr_run_cmd_list(cmd *commander.Command, args []string) error {
var err error
siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)
debug := cmd.Flag.Lookup("v").Value.Get().(bool)
name := ""
vers := ""
release := ""
switch len(args) {
case 0:
name = ""
case 1:
name = args[0]
case 2:
name = args[0]
vers = args[1]
case 3:
name = args[0]
vers = args[1]
release = args[2]
default:
cmd.Usage()
return fmt.Errorf("lbpkr: invalid number of arguments. expected n=0|1|2|3. got=%d (%v)",
len(args),
args,
)
}
cfg := NewConfig(siteroot)
ctx, err := New(cfg, Debug(debug))
if err != nil {
return err
}
defer ctx.Close()
_, err = ctx.ListPackages(name, vers, release)
return err
}