Skip to content

Commit

Permalink
Add git status command #13
Browse files Browse the repository at this point in the history
- FIXME: cant get the std error when git command is not executed correctly
  • Loading branch information
at15 committed Jan 15, 2016
1 parent 32e8518 commit a4d3437
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
14 changes: 8 additions & 6 deletions Ayi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"os"

"github.com/codegangsta/cli"
"github.com/dyweb/Ayi/app"
"github.com/dyweb/Ayi/sys"
"github.com/dyweb/Ayi/util"
)

func main() {
app := cli.NewApp()
app.Name = "Ayi"
app.Usage = "Let Ayi do it for you"
app.Commands = []cli.Command{
application := cli.NewApp()
application.Name = "Ayi"
application.Usage = "Let Ayi do it for you"
application.Commands = []cli.Command{
{
// Ayi like roast mie
Name: "mie",
Expand All @@ -24,7 +25,8 @@ func main() {
},
util.DummyCommand,
util.ServeStaticCommand,
sys.HostCommand,
sys.HostCommands,
app.GitCommands,
}
app.Run(os.Args)
application.Run(os.Args)
}
28 changes: 26 additions & 2 deletions app/command.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package app

import (
// "github.com/dyweb/Ayi/app/git"
)
"github.com/codegangsta/cli"
"github.com/dyweb/Ayi/app/git"
"log"
)

// GitCommands wrap common git operations with config defined in Ayi
var GitCommands = cli.Command{
Name: "git",
Aliases: []string{"g"},
Usage: "git command wrapper",
Subcommands: []cli.Command{
{
Name: "status",
Aliases: []string{"s"},
Usage: "git status",
Action: func(c *cli.Context) {
out, err, e := git.Status{}.Execute()
if e != nil {
println(err)
log.Fatal(e)
}
println(out)
},
},
},
}
29 changes: 28 additions & 1 deletion app/git/wrapper.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
package git

// wrap git command for clone
import (
"os/exec"
)

var cmdName = "git"

// simpleCommand is a interface execute and return output as string
type simpleCommand interface {
Execute() (stdOut string, stdErr string, err error)
}

// Status execute git status command and return output
type Status struct {
}

// Execute execute git status and return output as string
func (s Status) Execute() (stdOut string, stdErr string, err error) {
var cmdOut []byte
err = nil
cmdArgs := []string{"status"}
cmdOut, err = exec.Command(cmdName, cmdArgs...).Output()
// FIXME: cant get correct error output
if err != nil{
stdErr = err.Error()
}
// TODO: get return code?
return string(cmdOut), stdErr, err
}
4 changes: 2 additions & 2 deletions sys/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/go-errors/errors"
)

// HostCommand for list and modify host file
var HostCommand = cli.Command{
// HostCommands for list and modify host file
var HostCommands = cli.Command{
Name: "hosts",
Aliases: []string{"host"},
Usage: "config/show host",
Expand Down

0 comments on commit a4d3437

Please sign in to comment.