1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00

all: updates for new gonuts/commander api

This commit is contained in:
Sebastien Binet 2013-12-19 14:19:22 +01:00
parent 7aa11042f1
commit b4e82b788e
2 changed files with 14 additions and 20 deletions

View File

@ -2,11 +2,12 @@ package main
import ( import (
"fmt" "fmt"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
"os" "os"
"text/template" "text/template"
"unicode" "unicode"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
) )
func generate() *commander.Command { func generate() *commander.Command {
@ -29,10 +30,10 @@ type Generate struct {
Name string Name string
} }
func doGenerate(cmd *commander.Command, args []string) { func doGenerate(cmd *commander.Command, args []string) error {
if len(args) == 0 { if len(args) == 0 {
fmt.Println(cmd.Long) fmt.Println(cmd.Long)
return return nil
} }
pwd, _ := os.Getwd() pwd, _ := os.Getwd()
dir := fmt.Sprintf("%s/gobot-%s", pwd, args[0]) dir := fmt.Sprintf("%s/gobot-%s", pwd, args[0])
@ -69,7 +70,7 @@ func doGenerate(cmd *commander.Command, args []string) {
} }
driver, _ := template.New("").Parse(driver()) driver, _ := template.New("").Parse(driver())
driver.Execute(f, name) driver.Execute(f, name)
f.Close() return f.Close()
} }
func adaptor() string { func adaptor() string {

View File

@ -2,36 +2,29 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/gonuts/commander" "github.com/gonuts/commander"
"github.com/gonuts/flag" "github.com/gonuts/flag"
"os"
) )
var g_cmd *commander.Commander var g_cmd *commander.Command
func init() { func init() {
g_cmd = &commander.Commander{ g_cmd = &commander.Command{
Name: os.Args[0], UsageLine: "gobot <command>",
Commands: []*commander.Command{ Subcommands: []*commander.Command{
generate(), generate(),
}, },
Flag: flag.NewFlagSet("gobot", flag.ExitOnError), Flag: *flag.NewFlagSet("gobot", flag.ExitOnError),
} }
} }
func main() { func main() {
err := g_cmd.Flag.Parse(os.Args[1:]) err := g_cmd.Dispatch(os.Args[1:])
if err != nil { if err != nil {
fmt.Printf("**err**: %v\n", err) fmt.Printf("**err**: %v\n", err)
os.Exit(1) os.Exit(1)
} }
args := g_cmd.Flag.Args()
err = g_cmd.Run(args)
if err != nil {
fmt.Printf("**err**: %v\n", err)
os.Exit(1)
}
return return
} }