Created
April 20, 2013 21:10
-
-
Save mcuadros/5427447 to your computer and use it in GitHub Desktop.
Just playing with Go Flags (http://godoc.org/github.com/jessevdk/go-flags) an example with Commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/jessevdk/go-flags" | |
"os" | |
"strings" | |
) | |
func main() { | |
parser := flags.NewNamedParser("test", flags.Default) | |
parser.AddCommand("example", "Example", "A example of a command", new(Command)) | |
// Parse flags | |
_, err := parser.Parse() | |
if err != nil { | |
os.Exit(1) | |
} | |
} | |
type Command struct { | |
Offset uint `long:"offset" description:"Offset"` | |
} | |
func (c *Command) Execute(args []string) error { | |
fmt.Printf("Offset: %d\n", c.Offset) | |
fmt.Printf("Test args: %s\n", strings.Join(args, ", ")) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment