Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ NAME

SYNOPSIS
{{.Name}} create [-l|--language] [-t|--template] [-r|--repository]
[-c|--confirm] [-v|--verbose] [path]
[-p |--path] [-c|--confirm] [-v|--verbose]

DESCRIPTION
Creates a new function project.
Expand Down Expand Up @@ -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)
Expand All @@ -90,7 +90,10 @@ 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 ($FUNC_PATH)")

addVerboseFlag(cmd, cfg.Verbose)

// Help Action
Expand Down Expand Up @@ -173,22 +176,29 @@ 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")

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.
dirName, absolutePath = deriveNameAndAbsolutePathFromPath(path)

// 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,
Expand All @@ -198,6 +208,7 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory)
Confirm: viper.GetBool("confirm"),
Verbose: viper.GetBool("verbose"),
}

// If not in confirm/prompting mode, this cfg structure is complete.
if !cfg.Confirm {
return
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/func_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NAME

SYNOPSIS
func create [-l|--language] [-t|--template] [-r|--repository]
[-c|--confirm] [-v|--verbose] [path]
[-p |--path] [-c|--confirm] [-v|--verbose]

DESCRIPTION
Creates a new function project.
Expand Down Expand Up @@ -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 ($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)
Expand Down
Loading