Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passthrough passes through a flag as positional #463

Open
dbohdan opened this issue Oct 26, 2024 · 0 comments
Open

passthrough passes through a flag as positional #463

dbohdan opened this issue Oct 26, 2024 · 0 comments

Comments

@dbohdan
Copy link

dbohdan commented Oct 26, 2024

I have found a surprising passthrough behavior in Kong v1.2.1. The following example demonstrates it.

package main

import (
	"encoding/json"
	"fmt"

	"github.com/alecthomas/kong"
)

type cli struct {
	Command string   `arg:"" passthrough:""`
	Args    []string `arg:"" optional:"" name:"args"`
	Timeout float64  `short:"t" default:"0"`
}

func main() {
	var cliConfig cli
	kong.Parse(&cliConfig)

	m, err := json.Marshal(cliConfig)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(string(m))
}
$ ./foo -t 9 ls -la
{"Command":"ls","Args":["-la"],"Timeout":9}
$ ./foo -t 9 -la
{"Command":"-l","Args":["a"],"Timeout":9}

Kong takes the first flag and passes it through as a positional argument. It seems like this should be an error. Instead of -l becoming a positional argument, I expected it to be treated as an unknown flag and flags to only be passed through after a non-flag argument.

Edit: I have just learned about github.com/alecthomas/repr. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@dbohdan and others