Created
January 17, 2016 03:07
-
-
Save cynipe/ee6e87db0a44d9b18762 to your computer and use it in GitHub Desktop.
Golang CLI Example
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 ( | |
"os" | |
"fmt" | |
"github.com/mitchellh/cli" | |
) | |
func main() { | |
app := cli.NewCLI("hello", "0.0.0") | |
app.Args = os.Args[1:] | |
app.Commands = map[string]cli.CommandFactory { | |
"hello sub1": func() (cli.Command, error) { | |
return &Hello{}, nil | |
}, | |
"hello sub2 subsub1": func() (cli.Command, error) { | |
return &Hello{}, nil | |
}, | |
"hello sub2 subsub2": func() (cli.Command, error) { | |
return &Hello{}, nil | |
}, | |
} | |
status, err := app.Run() | |
if err != nil { | |
fmt.Println(err) | |
} | |
os.Exit(status) | |
} | |
type Hello struct { | |
} | |
func (*Hello) Help() string { | |
return "hello" | |
} | |
func (*Hello) Run(args []string) int { | |
fmt.Printf("hello, %v", args) | |
return 0 | |
} | |
func (h *Hello) Synopsis() string { | |
return h.Help() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment