Skip to content

No more positionals after a positional slice or map#287

Merged
alexflint merged 2 commits into
masterfrom
no-positionals-after-multipositional
Oct 7, 2025
Merged

No more positionals after a positional slice or map#287
alexflint merged 2 commits into
masterfrom
no-positionals-after-multipositional

Conversation

@alexflint
Copy link
Copy Markdown
Owner

@alexflint alexflint commented Jul 12, 2025

With this PR, go-arg returns an error if you define more positional arguments after a positional slice or map. Such positional arguments cannot be populated by go-arg. This could break programs that define positional arguments after positional slices or maps, but for whatever reason never need them to be populated by go-arg.

#265

@plutonium-239
Copy link
Copy Markdown

Hey, so does this mean even the following use case is unsupported? (Essentially args for a copy program)
Taken from Positional Arguments Example, slightly modified to interchange slice being first:

var args struct {
	Input   []string  `arg:"positional"`
	Output  string    `arg:"positional"`
}

So that the desired command is ./copy input1 input2 input3 output-dir/

I'm currently working on rbcp that already uses go-arg, but I was trying to add a new feature that would require this.

@alexflint
Copy link
Copy Markdown
Owner Author

Hey @plutonium-239 yeah that is correct... unfortunately. The case you describe does not work at present, though it would be reasonably simple to add support for it. It's actually quite amazing that it's never been requested before. I'll add it to my TODOs.

@alexflint alexflint merged commit 45c7f7b into master Oct 7, 2025
3 checks passed
@alexflint alexflint deleted the no-positionals-after-multipositional branch October 7, 2025 21:15
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

Successfully merging this pull request may close these issues.

2 participants