diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 72 |
1 files changed, 53 insertions, 19 deletions
diff --git a/main.go b/main.go index 158c9a566a86..de734e8ac37d 100644 --- a/main.go +++ b/main.go @@ -4,36 +4,70 @@ import ( "fmt" "os" + "github.com/polydawn/meep" "github.com/tazjin/kontemplate/context" "github.com/tazjin/kontemplate/templater" + "github.com/urfave/cli" ) func main() { - args := os.Args[1:] - if len(args) == 0 { - fmt.Fprintln(os.Stderr, "Usage: kontemplate <cluster-config>") - os.Exit(1) - } + app := cli.NewApp() - c, err := context.LoadContextFromFile(os.Args[1]) + app.Name = "kontemplate" + app.Usage = "simple Kubernetes resource templating" + app.Version = "0.0.1" - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - os.Exit(1) + app.Commands = []cli.Command{ + ApplyCommand(), } - fmt.Fprintf(os.Stderr, "Applying cluster %s\n", c.Name) + app.Run(os.Args) +} + +func ApplyCommand() cli.Command { + return cli.Command{ + Name: "run", + Usage: "Interpolate and print templates", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "file, f", + Usage: "Cluster configuration file to use", + }, + cli.StringSliceFlag{ + Name: "limit, l", + Usage: "Limit templating to certain resource sets", + }, + }, + Action: func(c *cli.Context) error { + limit := c.StringSlice("limit") + f := c.String("file") + + if f == "" { + return meep.New( + &meep.ErrInvalidParam{ + Param: "file", + Reason: "Cluster config file must be specified", + }, + ) + } + + ctx, err := context.LoadContextFromFile(f) + + if err != nil { + return err + } + + resources, err := templater.LoadAndPrepareTemplates(&limit, ctx) - for _, rs := range c.ResourceSets { - fmt.Fprintf(os.Stderr, "Applying resource %s with values %v\n", rs.Name, rs.Values) - resources, err := templater.LoadAndPrepareTemplates(c) + if err != nil { + return err + } - if err != nil { - fmt.Println(err) - } + for _, r := range resources { + fmt.Println(r) + } - for _, r := range resources { - fmt.Print(r) - } + return nil + }, } } |