If flag
package or a third-party library doesn’t provide the features you want, you can parse the arguments yourself.
https://codeeval.dev/gist/05dbb9a96658059fb7937ba1164e71e5
The above output is a result of go run $file -echo echo-arg additional arg
.
Raw command-line arguments can be accessed via []string
slice os.Args
.
First element is name of the executable.
Remaining elements are cmd-line arguments as decoded by OS shell.
On Windows cmd-line arguments are a single UTF-16 Unicode string.
Go runtime converts them to UTF-8 string and splits into separate arguments to unify handling across different operating systems.