Skip to content

Commit

Permalink
Merge pull request hybridgroup#15 from sbinet/new-commander-api
Browse files Browse the repository at this point in the history
all: updates for new gonuts/commander api
  • Loading branch information
zankich committed Feb 25, 2014
2 parents 59120cb + b4e82b7 commit 375d4ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
11 changes: 6 additions & 5 deletions gobot/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"fmt"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
"os"
"text/template"
"unicode"

"github.com/gonuts/commander"
"github.com/gonuts/flag"
)

func generate() *commander.Command {
Expand All @@ -29,10 +30,10 @@ type Generate struct {
Name string
}

func doGenerate(cmd *commander.Command, args []string) {
func doGenerate(cmd *commander.Command, args []string) error {
if len(args) == 0 {
fmt.Println(cmd.Long)
return
return nil
}
pwd, _ := os.Getwd()
dir := fmt.Sprintf("%s/gobot-%s", pwd, args[0])
Expand Down Expand Up @@ -69,7 +70,7 @@ func doGenerate(cmd *commander.Command, args []string) {
}
driver, _ := template.New("").Parse(driver())
driver.Execute(f, name)
f.Close()
return f.Close()
}

func adaptor() string {
Expand Down
23 changes: 8 additions & 15 deletions gobot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,29 @@ package main

import (
"fmt"
"os"

"github.com/gonuts/commander"
"github.com/gonuts/flag"
"os"
)

var g_cmd *commander.Commander
var g_cmd *commander.Command

func init() {
g_cmd = &commander.Commander{
Name: os.Args[0],
Commands: []*commander.Command{
g_cmd = &commander.Command{
UsageLine: "gobot <command>",
Subcommands: []*commander.Command{
generate(),
},
Flag: flag.NewFlagSet("gobot", flag.ExitOnError),
Flag: *flag.NewFlagSet("gobot", flag.ExitOnError),
}
}

func main() {
err := g_cmd.Flag.Parse(os.Args[1:])
err := g_cmd.Dispatch(os.Args[1:])
if err != nil {
fmt.Printf("**err**: %v\n", err)
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
}

0 comments on commit 375d4ab

Please sign in to comment.