github.com/Yunsang-Jeong/terraforge@v0.0.0-20231003081416-fe4fad2c57e3/cmd/run.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/Yunsang-Jeong/terraforge/internal/app"
     5  
     6  	"github.com/spf13/cobra"
     7  )
     8  
     9  type RunCmd struct{}
    10  
    11  var runCmdFlags = map[string]flag{
    12  	"debug": {
    13  		_type:        "bool",
    14  		shorten:      "d",
    15  		description:  "[opt] enable debug mode",
    16  		requirement:  false,
    17  		defaultValue: false,
    18  	},
    19  	"wd": {
    20  		_type:        "string",
    21  		shorten:      "w",
    22  		description:  "[opt] working directroy",
    23  		requirement:  false,
    24  		defaultValue: ".",
    25  	},
    26  	"cf": {
    27  		_type:        "string",
    28  		shorten:      "c",
    29  		description:  "[opt] config file name",
    30  		requirement:  false,
    31  		defaultValue: "terraforge.hcl",
    32  	},
    33  }
    34  
    35  func (r *RunCmd) Init() *cobra.Command {
    36  	c := &cobra.Command{
    37  		Use:   "run",
    38  		Short: "Genraete Terraform configuration",
    39  		Run: func(cmd *cobra.Command, args []string) {
    40  			debug, _ := cmd.Flags().GetBool("debug")
    41  			wd, _ := cmd.Flags().GetString("wd")
    42  			cf, _ := cmd.Flags().GetString("cf")
    43  
    44  			app.NewTerraforge(wd, cf, debug).Run()
    45  		},
    46  	}
    47  
    48  	cobraFlagRegister(c, runCmdFlags)
    49  
    50  	return c
    51  }