Skip to content

pkg/util/embed/flag.go: Support short flags with more than one character #3288

@Saurabh825

Description

@Saurabh825

Request

Currently, embedding short flags that contain more than one character results in an error.

error: unknown shorthand flag: 'c' in -certreq
error: no candidates
~> keytool -certreq -   

Short flags with more than one character (e.g., -certreq) should be parsed as a whole instead of being truncated to the first two characters.

Proposed solution

diff --git a/pkg/util/embed/flag.go b/pkg/util/embed/flag.go
index c0f8e18f..f7ca839a 100644
--- a/pkg/util/embed/flag.go
+++ b/pkg/util/embed/flag.go
@@ -31,7 +31,7 @@ func subcommandsAsFlags(cmd *cobra.Command, shorthandOnly bool, subcommands ...*
 		case strings.HasPrefix(args[0], "--"):
 			flags.Parse(args[:1])
 		case strings.HasPrefix(args[0], "-") && len(args[0]) > 1:
-			flags.Parse([]string{args[0][:2]})
+			flags.Parse([]string{args[0]})
 		}
 
 		var subcommand *cobra.Command

This works, but I am not sure if it breaks anything else.

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfundFundable with polar.sh

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions