-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_dump_template.go
53 lines (43 loc) · 1.04 KB
/
cmd_dump_template.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
package main
import (
"flag"
"fmt"
"github.com/mitchellh/cli"
)
//
// Implement the "dump-template" command
type CmdDumpTemplate struct {
CmdDefault
Template string
}
func CmdDumpTemplateFactory(ui cli.Ui) func() (cli.Command, error) {
return func() (cli.Command, error) {
return &CmdDumpTemplate{
CmdDefault: CmdDefault{Ui: ui},
}, nil
}
}
func (c *CmdDumpTemplate) Run(args []string) int {
c.InitFlagSet()
c.FS.StringVar(&c.Template, "template", "",
"The name of the template to dump: /templates/{dynamic-inventory,etc-hosts}.")
if err := c.FS.Parse(args); err != nil {
if err != flag.ErrHelp {
c.Ui.Error(fmt.Sprintf("Unable to parse arguments: %s", err))
}
return 1
}
if c.Template == "" {
c.Ui.Error("Missing template argument\n" + c.Help())
return 1
}
tString, err := FSString(isDev, c.Template)
if err != nil {
c.Ui.Error(fmt.Sprintf("Unable to read template: %s", err))
}
c.Ui.Output(tString)
return 0
}
func (c *CmdDumpTemplate) Synopsis() string {
return "Dump one of roster's built in templates."
}