/
output.go
44 lines (37 loc) · 963 Bytes
/
output.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
package plural
import (
"path/filepath"
"github.com/pluralsh/plural-cli/pkg/output"
"github.com/pluralsh/plural-cli/pkg/utils"
"github.com/pluralsh/plural-cli/pkg/utils/pathing"
"github.com/urfave/cli"
)
func outputCommands() []cli.Command {
return []cli.Command{
{
Name: "terraform",
Usage: "generates terraform output",
ArgsUsage: "REPO",
Action: latestVersion(handleTerraformOutput),
},
}
}
func outputPath(root, app string) string {
return pathing.SanitizeFilepath(filepath.Join(root, app, "output.yaml"))
}
func handleTerraformOutput(c *cli.Context) (err error) {
root, _ := utils.ProjectRoot()
app := c.Args().Get(0)
path := outputPath(root, app)
out, err := output.Read(path)
if err != nil {
out = output.New()
}
tfOut, err := output.TerraformOutput(pathing.SanitizeFilepath(filepath.Join(root, app, "terraform")))
if err != nil {
return
}
out.Terraform = tfOut
err = out.Save(app, path)
return
}