-
Notifications
You must be signed in to change notification settings - Fork 37
/
file_flags.go
51 lines (42 loc) · 1.15 KB
/
file_flags.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
package cmd
import (
ctlconf "github.com/k14s/kbld/pkg/kbld/config"
ctlres "github.com/k14s/kbld/pkg/kbld/resources"
"github.com/spf13/cobra"
)
type FileFlags struct {
Files []string
Recursive bool
Sort bool
}
func (s *FileFlags) Set(cmd *cobra.Command) {
cmd.Flags().StringSliceVarP(&s.Files, "file", "f", nil, "Set file (format: /tmp/foo, https://..., -) (can be specified multiple times)")
cmd.Flags().BoolVar(&s.Sort, "sort", true, "Sort by namespace, name, etc.")
}
func (f *FileFlags) AllResources() ([]ctlres.Resource, error) {
var rs []ctlres.Resource
// TODO do anything with kbld configs?
for _, file := range f.Files {
fileRs, err := ctlres.NewFileResources(file)
if err != nil {
return nil, err
}
for _, fileRes := range fileRs {
resources, err := fileRes.Resources()
if err != nil {
return nil, err
}
for _, res := range resources {
rs = append(rs, res)
}
}
}
return rs, nil
}
func (f *FileFlags) ResourcesAndConfig() ([]ctlres.Resource, ctlconf.Conf, error) {
allRs, err := f.AllResources()
if err != nil {
return nil, ctlconf.Conf{}, err
}
return ctlconf.NewConfFromResources(allRs)
}