Make instance path a required arg

This commit is contained in:
Shreyas Goenka 2023-06-21 18:40:15 +02:00
parent aabb574749
commit 63df93c1a1
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 5 additions and 7 deletions

View File

@ -6,20 +6,18 @@ import (
) )
var initCmd = &cobra.Command{ var initCmd = &cobra.Command{
Use: "init", Use: "init TEMPLATE_PATH INSTANCE_PATH",
Short: "Initialize Template", Short: "Initialize Template",
Long: `Initialize template`, Long: `Initialize template`,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return template.Materialize(args[0], targetDir, configFile) return template.Materialize(args[0], args[1], configFile)
}, },
} }
var targetDir string
var configFile string var configFile string
func init() { func init() {
initCmd.Flags().StringVar(&targetDir, "target-dir", ".", "path to directory template will be initialized in")
initCmd.Flags().StringVar(&configFile, "config-file", "", "path to config to use for template initialization") initCmd.Flags().StringVar(&configFile, "config-file", "", "path to config to use for template initialization")
initCmd.MarkFlagRequired("config-file") initCmd.MarkFlagRequired("config-file")
AddCommand(initCmd) AddCommand(initCmd)

View File

@ -36,7 +36,7 @@ func TestTemplateInitializationForDevConfig(t *testing.T) {
// materialize the template // materialize the template
cmd := root.RootCmd cmd := root.RootCmd
cmd.SetArgs([]string{"bundle", "init", filepath.FromSlash("testdata/init/templateDefinition"), "--target-dir", tmp, "--config-file", filepath.Join(tmp, "config.json")}) cmd.SetArgs([]string{"bundle", "init", filepath.FromSlash("testdata/init/templateDefinition"), tmp, "--config-file", filepath.Join(tmp, "config.json")})
err = cmd.Execute() err = cmd.Execute()
require.NoError(t, err) require.NoError(t, err)
@ -78,7 +78,7 @@ func TestTemplateInitializationForProdConfig(t *testing.T) {
cmd := root.RootCmd cmd := root.RootCmd
childCommands := cmd.Commands() childCommands := cmd.Commands()
fmt.Println(childCommands) fmt.Println(childCommands)
cmd.SetArgs([]string{"bundle", "init", filepath.FromSlash("testdata/init/templateDefinition"), "--target-dir", instanceDir, "--config-file", filepath.Join(configDir, "my_config.json")}) cmd.SetArgs([]string{"bundle", "init", filepath.FromSlash("testdata/init/templateDefinition"), instanceDir, "--config-file", filepath.Join(configDir, "my_config.json")})
err = cmd.Execute() err = cmd.Execute()
require.NoError(t, err) require.NoError(t, err)