-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.go
49 lines (40 loc) · 1003 Bytes
/
files.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
// Copyright 2017 Ruda Moura. All rights reserved.
package main
import (
"fmt"
"os"
"os/exec"
)
var cmdFiles = &Command{
Run: runFiles,
UsageLine: "files [-volume path] [packages]",
Short: "list files from packages",
Long: `
List files from installed packages.
The -volume flag instructs to perform operation on the specified volume. By
default, it uses the root volume "/".
See also: pkg info, pkg which.
`,
}
var filesVolume = "/"
func init() {
cmdFiles.Flag.StringVar(&filesVolume, "volume", "/", "")
}
func filesPackage(pkg string, volume string) (output string, err error) {
cmd := exec.Command("pkgutil", "--volume", volume, "--files", pkg)
out, err := cmd.CombinedOutput()
return string(out), err
}
func runFiles(cmd *Command, args []string) {
if len(args) == 0 {
cmd.Usage()
}
for _, pkg := range args {
out, err := filesPackage(pkg, filesVolume)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", out)
continue
}
fmt.Printf("%s", out)
}
}