Skip to content

Instantly share code, notes, and snippets.

@mcuadros
Created April 20, 2013 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcuadros/5427447 to your computer and use it in GitHub Desktop.
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
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