github.com/pluralsh/plural-cli@v0.9.5/cmd/plural/output.go (about)

     1  package plural
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/pluralsh/plural-cli/pkg/output"
     7  	"github.com/pluralsh/plural-cli/pkg/utils"
     8  	"github.com/pluralsh/plural-cli/pkg/utils/pathing"
     9  	"github.com/urfave/cli"
    10  )
    11  
    12  func outputCommands() []cli.Command {
    13  	return []cli.Command{
    14  		{
    15  			Name:      "terraform",
    16  			Usage:     "generates terraform output",
    17  			ArgsUsage: "REPO",
    18  			Action:    latestVersion(handleTerraformOutput),
    19  		},
    20  	}
    21  }
    22  
    23  func outputPath(root, app string) string {
    24  	return pathing.SanitizeFilepath(filepath.Join(root, app, "output.yaml"))
    25  }
    26  
    27  func handleTerraformOutput(c *cli.Context) (err error) {
    28  	root, _ := utils.ProjectRoot()
    29  	app := c.Args().Get(0)
    30  	path := outputPath(root, app)
    31  	out, err := output.Read(path)
    32  	if err != nil {
    33  		out = output.New()
    34  	}
    35  
    36  	tfOut, err := output.TerraformOutput(pathing.SanitizeFilepath(filepath.Join(root, app, "terraform")))
    37  	if err != nil {
    38  		return
    39  	}
    40  
    41  	out.Terraform = tfOut
    42  	err = out.Save(app, path)
    43  	return
    44  }