forked from lhcb-org/lbpkr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_provides.go
57 lines (47 loc) · 1.28 KB
/
cmd_provides.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
package main
import (
"fmt"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
)
func lbpkr_make_cmd_provides() *commander.Command {
cmd := &commander.Command{
Run: lbpkr_run_cmd_provides,
UsageLine: "provides [options] <file>",
Short: "list all installed RPM packages providing the given file",
Long: `
provides lists all installed RPM packages providing the given file.
ex:
$ lbpkr provides gaudirun.py
GAUDI_v25r1_x86_64_slc6_gcc48_opt-1.0.0-1 (/opt/cern-sw/lhcb/GAUDI/GAUDI_v25r1/InstallArea/x86_64-slc6-gcc48-opt/scripts/gaudirun.py)
`,
Flag: *flag.NewFlagSet("lbpkr-provides", flag.ExitOnError),
}
add_default_options(cmd)
return cmd
}
func lbpkr_run_cmd_provides(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)
filename := ""
switch len(args) {
case 1:
filename = args[0]
default:
cmd.Usage()
return fmt.Errorf("lbpkr: invalid number of arguments. expected n=1. 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.Provides(filename)
return err
}