-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
57 lines (43 loc) · 1.04 KB
/
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
package value
import (
"fmt"
"github.com/rjeczalik/bigstruct/cmd/bigstruct/command"
"github.com/spf13/cobra"
)
func NewListCommand(app *command.App) *cobra.Command {
m := &listCmd{
App: app,
}
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "Lists values",
Args: cobra.NoArgs,
RunE: m.run,
SilenceUsage: true,
}
m.register(cmd)
return cmd
}
type listCmd struct {
*command.App
overlay string
prefix string
}
func (m *listCmd) register(cmd *cobra.Command) {
f := cmd.Flags()
f.StringVarP(&m.overlay, "overlay", "L", "", "")
f.StringVarP(&m.prefix, "prefix", "p", "/", "")
cmd.MarkFlagRequired("overlay")
}
func (m *listCmd) run(*cobra.Command, []string) error {
ns, err := m.Storage.Overlay(m.overlay)
if err != nil {
return fmt.Errorf("error loading %q overlay: %w", m.overlay, err)
}
v, err := m.Storage.ListValues(ns, m.prefix)
if err != nil {
return fmt.Errorf("error listing %q values for %q overlay: %w", m.prefix, ns.Ref(), err)
}
return m.Render(v)
}