func
func copied to clipboard
func create: Hyphen-prefixed names mis-parsed as flags
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
-tfrom-test-funcas the--templateshort flag - Remaining text
est-funcused 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
-lfrom-language-testas the--languageshort flag - Remaining text
anguage-testused 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
-cfrom-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.
/kind bug