views:

121

answers:

1

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?

+7  A: 

Nevermind.

package main

import "fmt"
import "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.

Jurily
very helpful to others, thanks!
Peter Lindqvist
Remember to mark this answer as correct, so people will knot that this question has already been answered.
Brian Campbell
I can't do that for my own answer for another two days.
Jurily
We know. He's saying in two days, don't forget.
Jed Smith
I heartily approve of you answering your own question.
C. Ross