Skip to content

func create: Hyphen-prefixed names mis-parsed as flags #3166

@RayyanSeliya

Description

@RayyanSeliya

Problem

When running func create with function names starting with a hyphen, the command mis-parses them as flags, resulting in confusing error messages that don't clearly indicate the naming issue.

Current Behavior

Scenario 1: Function name starting with hyphen (template flag conflict)

Command:

func create --language go -test-func

Current Output:

Error: The template 'est-func' was not found for language runtime 'go'.
Available templates for this language runtime are:
  cloudevents
  http

Problems:

  • Leading hyphen - interpreted as flag prefix
  • CLI parsed -t from -test-func as the --template short flag
  • Remaining text est-func used as template name
  • Error message doesn't mention the naming issue
  • No guidance that function names cannot start with hyphens

Scenario 2: Function name starting with hyphen (language flag conflict)

Command:

func create --language go -language-test

Current Output:

Error: The language runtime 'anguage-test' is not recognized.
Available language runtimes are:
  go
  node
  python
  quarkus
  rust
  springboot
  typescript

Problems:

  • CLI parsed -l from -language-test as the --language short flag
  • Remaining text anguage-test used as runtime name
  • Error message about invalid runtime instead of invalid name format
  • No indication that the argument was mis-parsed

Scenario 3: Function name starting with hyphen (invalid short flag)

Command:

func create --language go -custom-func

Current Output:

Error: unknown shorthand flag: 'u' in -ustom-func

Problems:

  • CLI parsed -c from -custom-func (no matching short flag exists)
  • Shows cryptic "unknown shorthand flag: 'u'" error
  • User doesn't understand why 'u' is being parsed as a flag
  • No guidance on valid naming rules

Scenario 4: Function name starting with double hyphen

Command:

func create --language go --production-func

Current Output:

Error: unknown flag: --production-func

Problems:

  • Double hyphen -- interpreted as long flag prefix
  • Generic "unknown flag" error
  • No indication this was meant to be a function name
  • No guidance on DNS-1035 naming rules

Scenario 5: Function name starting with hyphen and number

Command:

func create --language go -123

Current Output:

Error: unknown shorthand flag: '1' in -123

Problems:

  • Hyphen followed by number parsed as invalid short flag
  • Confusing error about flag '1'
  • No indication that numbers can't be flags
  • No guidance on valid function naming

Proposed Improvement

All scenarios above should display the original error message followed by a helpful note explaining the mis-parsing and DNS-1035 naming rules.

Example (Scenario 1):

Command:

func create --language go -test-func

Improved Output:

Error: The template 'est-func' was not found for language runtime 'go'.
Available templates for this language runtime are:
  cloudevents
  http

Note: It looks like '-test-func' was interpreted as the flag '-t' with value 'est-func'.
Function names cannot start with hyphens per DNS-1035 naming rules.
Valid function names must start with a letter (a-z) and can contain letters, numbers, and hyphens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions