/
describe.go
67 lines (57 loc) · 1.5 KB
/
describe.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 commands
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/anchore/clio"
"github.com/anchore/quill/cmd/quill/cli/options"
"github.com/anchore/quill/internal/bus"
"github.com/anchore/quill/quill/extract"
)
type describeConfig struct {
Path string `yaml:"path" json:"path" mapstructure:"-"`
options.Format `yaml:",inline" json:",inline" mapstructure:",squash"`
options.Describe `yaml:"describe" json:"describe" mapstructure:"describe"`
}
func Describe(app clio.Application) *cobra.Command {
opts := &describeConfig{
Format: options.Format{
Output: "text",
AllowableFormats: []string{"text", "json"},
},
}
return app.SetupCommand(&cobra.Command{
Use: "describe PATH",
Short: "show the details of a macho binary",
Example: options.FormatPositionalArgsHelp(
map[string]string{
"PATH": "the darwin binary to print details for",
},
),
Args: chainArgs(
cobra.ExactArgs(1),
func(_ *cobra.Command, args []string) error {
opts.Path = args[0]
return nil
},
),
RunE: func(cmd *cobra.Command, args []string) error {
defer bus.Exit()
var err error
buf := &strings.Builder{}
switch strings.ToLower(opts.Output) {
case "text":
err = extract.ShowText(opts.Path, buf, !opts.Detail)
case "json":
err = extract.ShowJSON(opts.Path, buf)
default:
err = fmt.Errorf("unknown format: %s", opts.Output)
}
if err != nil {
return err
}
bus.Report(buf.String())
return nil
},
}, opts)
}