Archimedes Trajano
Archimedes Trajano

Reputation: 41580

How would I implement in Cobra a sub-command that would accept extra parameters as is?

I'm trying to implement a command like this

var devCmd = &cobra.Command{
    Use:                "dev [flags] IMAGE COMMAND ...ARGS",
    Short:              "Run an image in a wormhole",

But if I have either

DisableFlagParsing: true,
FParseErrWhitelist: cobra.FParseErrWhitelist{
  UnknownFlags: true,
},

I lose the extra flag data I wanted it such that if I have the command which has a known parameters --force and --be-with-you

docker-cli dev --force caddy --be-with-you caddy format --overwrite --force ./Caddyfile

This function

RunE: func(cmd *cobra.Command, args []string) error {
   // args would have
   // caddy,
   // caddy,
   // format,
   // --overwrite
   // --force 
   // ./Caddyfile

Upvotes: 0

Views: 26

Answers (0)

Related Questions