Skip to content

Instantly share code, notes, and snippets.

@sysr-q
Created January 28, 2014 10:05
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 sysr-q/8665026 to your computer and use it in GitHub Desktop.
Save sysr-q/8665026 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"flag"
)
func help(args []string) {
help := []string{
"YO",
"THIS",
}
for _, line := range help {
fmt.Println(line)
}
}
func test(args []string) {
fmt.Println("test:", args)
}
func main() {
commands := map[string]func([]string){
"help": help,
"test": test,
}
flag.Parse()
cmd := flag.Arg(0)
if cmd == "" {
cmd = "help"
}
if f, ok := commands[cmd]; ok {
// Includes current `cmd`.
f(flag.Args())
} else {
help([]string{})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment