Skip to content

2024

Allowing flags anywhere on the CLI

Writing CLIs in Go is great, but there's one annoyance with the stdlib flag package:

flags must be defined before any positional arguments.

For example, if you have a --debug flag, you can't use it after a positional argument, it'll be treated as a 2nd positional argument.

# ✅ Works as expeceted
$ mycli --debug run

# ❌ Does not work as expected
$ mycli run --debug