Added debora cli

This commit is contained in:
Jae Kwon 2015-04-15 20:22:03 -07:00
parent 618cd18f8b
commit 58bcad3ea3
3 changed files with 76 additions and 19 deletions

View File

@ -2,18 +2,81 @@ package main
import ( import (
"fmt" "fmt"
"github.com/codegangsta/cli"
"io/ioutil"
"os"
"strings"
acm "github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
) )
func main() { func main() {
var remote string = "http://127.0.0.1:8082" fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())
var err error app := cli.NewApp()
var privKey acm.PrivKey app.Name = "debora"
binary.ReadJSON(&privKey, []byte(` app.Usage = "summons commands to barak"
[1,"PRIVKEYBYTES"] app.Version = "0.0.1"
`), &err) app.Email = "ethan@erisindustries.com,jae@tendermint.com"
response, err := ListProcesses(privKey, remote) app.Flags = []cli.Flag{}
fmt.Printf("%v (error: %v)\n", response, err) app.Commands = []cli.Command{
cli.Command{
Name: "list",
Usage: "list processes",
Action: cliListProcesses,
Flags: []cli.Flag{
remotesFlag,
privKeyFlag,
},
},
}
app.Run(os.Args)
}
var (
remotesFlag = cli.StringFlag{
Name: "remotes",
Value: "http://127.0.0.1:8082",
Usage: "comma separated list of remote baraks",
}
privKeyFlag = cli.StringFlag{
Name: "privkey-file",
Value: "privkey",
Usage: "file containing private key json",
}
)
func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) {
remotesStr := c.String("remotes")
remotes = strings.Split(remotesStr, ",")
privkeyFile := c.String("privkey-file")
privkeyJSONBytes, err := ioutil.ReadFile(privkeyFile)
if err != nil {
Exit(Fmt("Failed to read privkey from file %v. %v", privkeyFile, err))
}
binary.ReadJSON(&privKey, privkeyJSONBytes, &err)
if err != nil {
Exit(Fmt("Failed to parse privkey. %v", err))
}
return remotes, privKey
}
func cliListProcesses(c *cli.Context) {
remotes, privKey := ParseFlags(c)
/*
args := c.Args()
if len(args) == 0 {
log.Fatal("Must specify application name")
}
app := args[0]
*/
for _, remote := range remotes {
response, err := ListProcesses(privKey, remote)
if err != nil {
fmt.Printf("%v failed. %v\n", remote, err)
} else {
fmt.Printf("%v processes: %v\n", remote, response.Processes)
}
}
} }

View File

@ -20,3 +20,8 @@ func TrapSignal(cb func()) {
}() }()
select {} select {}
} }
func Exit(s string) {
fmt.Printf(s + "\n")
os.Exit(1)
}

View File

@ -1,11 +0,0 @@
package common
import (
"fmt"
"os"
)
func Exit(s string) {
fmt.Printf(s)
os.Exit(1)
}