From 145fcd39c8c01ef32e25a5ad2af004670b9ec072 Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Fri, 17 Oct 2025 20:16:47 +0000 Subject: [PATCH 1/8] created path flag --- cmd/create.go | 37 ++++++++++++++++++++++++++++------- docs/reference/func_create.md | 3 ++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index ef77eca7e6..8039015741 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -37,7 +37,7 @@ NAME SYNOPSIS {{.Name}} create [-l|--language] [-t|--template] [-r|--repository] - [-c|--confirm] [-v|--verbose] [path] + [--path ] [-c|--confirm] [-v|--verbose] DESCRIPTION Creates a new function project. @@ -90,7 +90,15 @@ EXAMPLES cmd.Flags().StringP("repository", "r", "", "URI to a Git repository containing the specified template ($FUNC_REPOSITORY)") addConfirmFlag(cmd, cfg.Confirm) - // TODO: refactor to use --path like all the other commands + // Add --path flag (default ".") for consistency with other commands. + // Retain positional [path] for backward compatibility (warned later). + cmd.Flags().StringP("path", "p", ".", "Path to the function project directory (default: current directory) ($FUNC_PATH)") + + // Bind the --path flag to viper so it can be read in newCreateConfig + if err := viper.BindPFlag("path", cmd.Flags().Lookup("path")); err != nil { + fmt.Fprintf(os.Stderr, "unable to bind path flag: %v\n", err) + } + addVerboseFlag(cmd, cfg.Verbose) // Help Action @@ -113,9 +121,11 @@ func runCreate(cmd *cobra.Command, args []string, newClient ClientFactory) (err // Create a config based on args. Also uses the newClient to create a // temporary client for completing options such as available runtimes. cfg, err := newCreateConfig(cmd, args, newClient) + fmt.Printf("DEBUG: cfg.Path = %s\n", cfg.Path) if err != nil { return } + // Client // From environment variables, flags, arguments, and user prompts if --confirm @@ -131,6 +141,7 @@ func runCreate(cmd *cobra.Command, args []string, newClient ClientFactory) (err return } + // Create _, err = client.Init(fn.Function{ Name: cfg.Name, @@ -173,19 +184,16 @@ type createConfig struct { // current value of the config at time of prompting. func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) (cfg createConfig, err error) { var ( - path string + pathFlag string dirName string absolutePath string ) - if len(args) >= 1 { - path = args[0] - } + pathFlag = viper.GetString("path") // Convert the path to an absolute path, and extract the ending directory name // as the function name. TODO: refactor to be git-like with no name up-front // and set instead as a named one-to-many deploy target. - dirName, absolutePath = deriveNameAndAbsolutePathFromPath(path) // Config is the final default values based off the execution context. // When prompting, these become the defaults presented. @@ -198,6 +206,19 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) Confirm: viper.GetBool("confirm"), Verbose: viper.GetBool("verbose"), } + + finalPath := "." + if pathFlag != "" && pathFlag != "." { + finalPath = pathFlag + } else if len(args) >= 1 && args[0] != "" { + finalPath = args[0] + } + + dirName, absolutePath = deriveNameAndAbsolutePathFromPath(finalPath) + + cfg.Name = dirName + cfg.Path = absolutePath + // If not in confirm/prompting mode, this cfg structure is complete. if !cfg.Confirm { return @@ -218,6 +239,8 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) fmt.Println(singleCommand(cmd, args, createdCfg)) return createdCfg, nil } + fmt.Printf("DEBUG: Using path: %s\n", cfg.Path) + // Confirming, but noninteractive // Print out the final values as a confirmation. Only show Repository or diff --git a/docs/reference/func_create.md b/docs/reference/func_create.md index 4dfb841d1f..9e0307e18a 100644 --- a/docs/reference/func_create.md +++ b/docs/reference/func_create.md @@ -10,7 +10,7 @@ NAME SYNOPSIS func create [-l|--language] [-t|--template] [-r|--repository] - [-c|--confirm] [-v|--verbose] [path] + [--path ] [-c|--confirm] [-v|--verbose] DESCRIPTION Creates a new function project. @@ -70,6 +70,7 @@ func create -c, --confirm Prompt to confirm options interactively ($FUNC_CONFIRM) -h, --help help for create -l, --language string Language Runtime (see help text for list) ($FUNC_LANGUAGE) + -p, --path string Path to the function project directory (default: current directory) ($FUNC_PATH) (default ".") -r, --repository string URI to a Git repository containing the specified template ($FUNC_REPOSITORY) -t, --template string Function template. (see help text for list) ($FUNC_TEMPLATE) (default "http") -v, --verbose Print verbose logs ($FUNC_VERBOSE) From 00b7e41f9ca1753170844c7b62380bdb06cd0913 Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Fri, 17 Oct 2025 20:21:21 +0000 Subject: [PATCH 2/8] typo-fixes --- cmd/create.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index 8039015741..abf5f250f9 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -121,11 +121,9 @@ func runCreate(cmd *cobra.Command, args []string, newClient ClientFactory) (err // Create a config based on args. Also uses the newClient to create a // temporary client for completing options such as available runtimes. cfg, err := newCreateConfig(cmd, args, newClient) - fmt.Printf("DEBUG: cfg.Path = %s\n", cfg.Path) if err != nil { return } - // Client // From environment variables, flags, arguments, and user prompts if --confirm @@ -141,7 +139,6 @@ func runCreate(cmd *cobra.Command, args []string, newClient ClientFactory) (err return } - // Create _, err = client.Init(fn.Function{ Name: cfg.Name, From 406542f405748ca23f6909ddd5ca216d8f099e80 Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Fri, 17 Oct 2025 20:30:03 +0000 Subject: [PATCH 3/8] typo-fix --- cmd/create.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index abf5f250f9..c57bb5d890 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -236,9 +236,7 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) fmt.Println(singleCommand(cmd, args, createdCfg)) return createdCfg, nil } - fmt.Printf("DEBUG: Using path: %s\n", cfg.Path) - - + // Confirming, but noninteractive // Print out the final values as a confirmation. Only show Repository or // Repositories, not both (repository takes precedence) in order to avoid From 62c10c5cd91fb18324176a36bf75ab3a508698d1 Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Sat, 18 Oct 2025 04:22:00 +0000 Subject: [PATCH 4/8] goimports --- cmd/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/create.go b/cmd/create.go index c57bb5d890..f2d54398ad 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -236,7 +236,7 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) fmt.Println(singleCommand(cmd, args, createdCfg)) return createdCfg, nil } - + // Confirming, but noninteractive // Print out the final values as a confirmation. Only show Repository or // Repositories, not both (repository takes precedence) in order to avoid From 5962c3e741715eb5a9c3fd0ff26fb1b8f2c68f79 Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Sat, 18 Oct 2025 07:17:24 +0000 Subject: [PATCH 5/8] fixes --- cmd/create.go | 24 +++++++++++------------- docs/reference/func_create.md | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index f2d54398ad..2958deac4a 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -37,7 +37,7 @@ NAME SYNOPSIS {{.Name}} create [-l|--language] [-t|--template] [-r|--repository] - [--path ] [-c|--confirm] [-v|--verbose] + [-p |--path] [-c|--confirm] [-v|--verbose] DESCRIPTION Creates a new function project. @@ -188,12 +188,22 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) pathFlag = viper.GetString("path") + finalPath := "." + if pathFlag != "" && pathFlag != "." { + finalPath = pathFlag + } else if len(args) >= 1 && args[0] != "" { + finalPath = args[0] + } + + dirName, absolutePath = deriveNameAndAbsolutePathFromPath(finalPath) + // Convert the path to an absolute path, and extract the ending directory name // as the function name. TODO: refactor to be git-like with no name up-front // and set instead as a named one-to-many deploy target. // Config is the final default values based off the execution context. // When prompting, these become the defaults presented. + cfg = createConfig{ Name: dirName, // TODO: refactor to be git-like Path: absolutePath, @@ -204,18 +214,6 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) Verbose: viper.GetBool("verbose"), } - finalPath := "." - if pathFlag != "" && pathFlag != "." { - finalPath = pathFlag - } else if len(args) >= 1 && args[0] != "" { - finalPath = args[0] - } - - dirName, absolutePath = deriveNameAndAbsolutePathFromPath(finalPath) - - cfg.Name = dirName - cfg.Path = absolutePath - // If not in confirm/prompting mode, this cfg structure is complete. if !cfg.Confirm { return diff --git a/docs/reference/func_create.md b/docs/reference/func_create.md index 9e0307e18a..8eef0746a5 100644 --- a/docs/reference/func_create.md +++ b/docs/reference/func_create.md @@ -10,7 +10,7 @@ NAME SYNOPSIS func create [-l|--language] [-t|--template] [-r|--repository] - [--path ] [-c|--confirm] [-v|--verbose] + [-p |--path] [-c|--confirm] [-v|--verbose] DESCRIPTION Creates a new function project. From ea274eb3ac5f56a15ef2962e3ae44eb870b81aaf Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Sat, 18 Oct 2025 08:00:48 +0000 Subject: [PATCH 6/8] required fixes --- cmd/create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index 2958deac4a..9bd122e260 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -92,7 +92,7 @@ EXAMPLES addConfirmFlag(cmd, cfg.Confirm) // Add --path flag (default ".") for consistency with other commands. // Retain positional [path] for backward compatibility (warned later). - cmd.Flags().StringP("path", "p", ".", "Path to the function project directory (default: current directory) ($FUNC_PATH)") + cmd.Flags().StringP("path", "p", ".", "Path to the function project directory ($FUNC_PATH)") // Bind the --path flag to viper so it can be read in newCreateConfig if err := viper.BindPFlag("path", cmd.Flags().Lookup("path")); err != nil { @@ -203,7 +203,7 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory) // Config is the final default values based off the execution context. // When prompting, these become the defaults presented. - + cfg = createConfig{ Name: dirName, // TODO: refactor to be git-like Path: absolutePath, From 20acb7ee28e2c82589cad3ff65b821b5866f95aa Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Sat, 18 Oct 2025 08:10:33 +0000 Subject: [PATCH 7/8] docs updated --- docs/reference/func_create.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/func_create.md b/docs/reference/func_create.md index 8eef0746a5..1f3ebc86a8 100644 --- a/docs/reference/func_create.md +++ b/docs/reference/func_create.md @@ -70,7 +70,7 @@ func create -c, --confirm Prompt to confirm options interactively ($FUNC_CONFIRM) -h, --help help for create -l, --language string Language Runtime (see help text for list) ($FUNC_LANGUAGE) - -p, --path string Path to the function project directory (default: current directory) ($FUNC_PATH) (default ".") + -p, --path string Path to the function project directory ($FUNC_PATH) (default ".") -r, --repository string URI to a Git repository containing the specified template ($FUNC_REPOSITORY) -t, --template string Function template. (see help text for list) ($FUNC_TEMPLATE) (default "http") -v, --verbose Print verbose logs ($FUNC_VERBOSE) From 764a87dc6853cfc1daf12b26bb5c76041c4c830e Mon Sep 17 00:00:00 2001 From: Anurag Ojha Date: Sat, 18 Oct 2025 12:00:09 +0000 Subject: [PATCH 8/8] fix/binding-path --- cmd/create.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index 9bd122e260..de5760b699 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -71,7 +71,7 @@ EXAMPLES $ {{.Name}} create -l go -t cloudevents myfunc `, SuggestFor: []string{"vreate", "creaet", "craete", "new"}, - PreRunE: bindEnv("language", "template", "repository", "confirm", "verbose"), + PreRunE: bindEnv("language", "template", "repository", "confirm", "verbose", "path"), Aliases: []string{"init"}, RunE: func(cmd *cobra.Command, args []string) error { return runCreate(cmd, args, newClient) @@ -94,11 +94,6 @@ EXAMPLES // Retain positional [path] for backward compatibility (warned later). cmd.Flags().StringP("path", "p", ".", "Path to the function project directory ($FUNC_PATH)") - // Bind the --path flag to viper so it can be read in newCreateConfig - if err := viper.BindPFlag("path", cmd.Flags().Lookup("path")); err != nil { - fmt.Fprintf(os.Stderr, "unable to bind path flag: %v\n", err) - } - addVerboseFlag(cmd, cfg.Verbose) // Help Action