-
Notifications
You must be signed in to change notification settings - Fork 12
/
templates.go
38 lines (29 loc) · 1008 Bytes
/
templates.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
package main
import "github.com/opcr-io/policy/pkg/errors"
type TemplatesCmd struct {
Apply ApplyCmd `cmd:"" name:"apply" help:"Create or update a policy or related artifacts from a template."`
List ListCmd `cmd:"" name:"list" help:"List all available templates."`
}
type ApplyCmd struct {
Template string `arg:"" name:"template" required:"true" help:"name of the template to apply"`
Output string `name:"output" short:"o" help:"output directory (defaults to current directory)" default:"."`
Overwrite bool `name:"overwrite" help:"overwrite existing files" default:"false"`
}
type ListCmd struct {
}
func (c *ApplyCmd) Run(g *Globals) error {
err := g.App.TemplateApply(c.Template, c.Output, c.Overwrite)
if err != nil {
return errors.TemplateFailed.WithError(err)
}
<-g.App.Context.Done()
return nil
}
func (c *ListCmd) Run(g *Globals) error {
err := g.App.TemplatesList()
if err != nil {
return errors.TemplateFailed.WithError(err)
}
<-g.App.Context.Done()
return nil
}