forked from lhcb-org/lbpkr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_installed.go
68 lines (58 loc) · 1.48 KB
/
cmd_installed.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
package main
import (
"fmt"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
)
func lbpkr_make_cmd_installed() *commander.Command {
cmd := &commander.Command{
Run: lbpkr_run_cmd_installed,
UsageLine: "installed [options] <name-pattern> [<version-pattern> [<release-pattern>]]",
Short: "list all installed RPM packages satisfying <name-pattern> [<version-pattern> [<release-pattern>]]",
Long: `
installed lists all installed RPM packages satisfying <name-pattern> [<version-pattern> [<release-pattern>]].
ex:
$ lbpkr installed GAUDI
$ lbpkr installed GAUDI v23r2
`,
Flag: *flag.NewFlagSet("lbpkr-installed", flag.ExitOnError),
}
add_default_options(cmd)
return cmd
}
func lbpkr_run_cmd_installed(cmd *commander.Command, args []string) error {
var err error
siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)
cfgtype := cmd.Flag.Lookup("type").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(cfgtype, siteroot)
ctx, err := New(cfg, debug)
if err != nil {
return err
}
defer ctx.Close()
_, err = ctx.ListInstalledPackages(name, vers, release)
return err
}