How do I get the command line arguments in Go without the “flags” package?
-
19-09-2019 - |
Question
I'm trying to write a GNU-style command-line parser for Go, since the flags
package doesn't handle all these yet:
program -aAtGc --long-option-1 argument-to-1 --long-option-2 -- real-argument
Obviously, I don't want to use the flags
package, since I'm trying to replace it. Is there any other way to get to the command line?
Solution
Nevermind.
package main
import (
"fmt"
"os"
)
func main() {
args := os.Args
fmt.Printf("%d\n", len(args))
for i := 0; i<len(args); i++ {
fmt.Printf("%s\n", args[i])
}
}
The documentation is quite incomplete, though.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow