fixed global flags
This commit is contained in:
parent
df1d46d04d
commit
adccd8f878
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
|
@ -8,13 +9,33 @@ import (
|
||||||
"github.com/tendermint/tendermint/rpc"
|
"github.com/tendermint/tendermint/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Convenience function for a single validator.
|
func RunProcess(privKey acm.PrivKey, remote string, command btypes.CommandRunProcess) (response btypes.ResponseRunProcess, err error) {
|
||||||
func ListProcesses(privKey acm.PrivKey, remote string) (btypes.ResponseListProcesses, error) {
|
nonce, err := GetNonce(remote)
|
||||||
command := btypes.CommandListProcesses{}
|
if err != nil {
|
||||||
nonce := GetNonce(remote)
|
return response, err
|
||||||
|
}
|
||||||
commandBytes, signature := SignCommand(privKey, nonce+1, command)
|
commandBytes, signature := SignCommand(privKey, nonce+1, command)
|
||||||
response := btypes.ResponseListProcesses{}
|
_, err = RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
|
||||||
_, err := RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func StopProcess(privKey acm.PrivKey, remote string, command btypes.CommandStopProcess) (response btypes.ResponseStopProcess, err error) {
|
||||||
|
nonce, err := GetNonce(remote)
|
||||||
|
if err != nil {
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
commandBytes, signature := SignCommand(privKey, nonce+1, command)
|
||||||
|
_, err = RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListProcesses(privKey acm.PrivKey, remote string, command btypes.CommandListProcesses) (response btypes.ResponseListProcesses, err error) {
|
||||||
|
nonce, err := GetNonce(remote)
|
||||||
|
if err != nil {
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
commandBytes, signature := SignCommand(privKey, nonce+1, command)
|
||||||
|
_, err = RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,14 +43,14 @@ func ListProcesses(privKey acm.PrivKey, remote string) (btypes.ResponseListProce
|
||||||
|
|
||||||
// Utility method to get nonce from the remote.
|
// Utility method to get nonce from the remote.
|
||||||
// The next command should include the returned nonce+1 as nonce.
|
// The next command should include the returned nonce+1 as nonce.
|
||||||
func GetNonce(remote string) uint64 {
|
func GetNonce(remote string) (uint64, error) {
|
||||||
var err error
|
var err error
|
||||||
response := btypes.ResponseStatus{}
|
response := btypes.ResponseStatus{}
|
||||||
_, err = rpc.Call(remote, "status", Arr(), &response)
|
_, err = rpc.Call(remote, "status", Arr(), &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error fetching nonce from remote %v: %v", remote, err))
|
return 0, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err)
|
||||||
}
|
}
|
||||||
return response.Nonce
|
return response.Nonce, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each developer runs this
|
// Each developer runs this
|
||||||
|
|
|
@ -9,32 +9,13 @@ import (
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
|
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())
|
|
||||||
app := cli.NewApp()
|
|
||||||
app.Name = "debora"
|
|
||||||
app.Usage = "summons commands to barak"
|
|
||||||
app.Version = "0.0.1"
|
|
||||||
app.Email = "ethan@erisindustries.com,jae@tendermint.com"
|
|
||||||
app.Flags = []cli.Flag{}
|
|
||||||
app.Commands = []cli.Command{
|
|
||||||
cli.Command{
|
|
||||||
Name: "list",
|
|
||||||
Usage: "list processes",
|
|
||||||
Action: cliListProcesses,
|
|
||||||
Flags: []cli.Flag{
|
|
||||||
remotesFlag,
|
|
||||||
privKeyFlag,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
app.Run(os.Args)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
remotes []string
|
||||||
|
privKey acm.PrivKey
|
||||||
remotesFlag = cli.StringFlag{
|
remotesFlag = cli.StringFlag{
|
||||||
Name: "remotes",
|
Name: "remotes",
|
||||||
Value: "http://127.0.0.1:8082",
|
Value: "http://127.0.0.1:8082",
|
||||||
|
@ -47,6 +28,53 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "debora"
|
||||||
|
app.Usage = "summons commands to barak"
|
||||||
|
app.Version = "0.0.1"
|
||||||
|
app.Email = "ethan@erisindustries.com,jae@tendermint.com"
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
remotesFlag,
|
||||||
|
privKeyFlag,
|
||||||
|
}
|
||||||
|
app.Before = func(c *cli.Context) error {
|
||||||
|
remotes, privKey = ParseFlags(c)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
cli.Command{
|
||||||
|
Name: "run",
|
||||||
|
Usage: "run process",
|
||||||
|
Action: cliRunProcess,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
//remotesFlag,
|
||||||
|
//privKeyFlag,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cli.Command{
|
||||||
|
Name: "stop",
|
||||||
|
Usage: "stop process",
|
||||||
|
Action: cliStopProcess,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
//remotesFlag,
|
||||||
|
//privKeyFlag,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cli.Command{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "list processes",
|
||||||
|
Action: cliListProcesses,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
//remotesFlag,
|
||||||
|
//privKeyFlag,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) {
|
func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) {
|
||||||
remotesStr := c.String("remotes")
|
remotesStr := c.String("remotes")
|
||||||
remotes = strings.Split(remotesStr, ",")
|
remotes = strings.Split(remotesStr, ",")
|
||||||
|
@ -62,8 +90,7 @@ func ParseFlags(c *cli.Context) (remotes []string, privKey acm.PrivKey) {
|
||||||
return remotes, privKey
|
return remotes, privKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func cliListProcesses(c *cli.Context) {
|
func cliRunProcess(c *cli.Context) {
|
||||||
remotes, privKey := ParseFlags(c)
|
|
||||||
/*
|
/*
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
|
@ -71,12 +98,51 @@ func cliListProcesses(c *cli.Context) {
|
||||||
}
|
}
|
||||||
app := args[0]
|
app := args[0]
|
||||||
*/
|
*/
|
||||||
|
command := btypes.CommandRunProcess{}
|
||||||
for _, remote := range remotes {
|
for _, remote := range remotes {
|
||||||
response, err := ListProcesses(privKey, remote)
|
response, err := RunProcess(privKey, remote, command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%v failed. %v\n", remote, err)
|
fmt.Printf("%v failure. %v\n", remote, err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%v processes: %v\n", remote, response.Processes)
|
fmt.Printf("%v success. %v\n", remote, response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cliStopProcess(c *cli.Context) {
|
||||||
|
/*
|
||||||
|
args := c.Args()
|
||||||
|
if len(args) == 0 {
|
||||||
|
log.Fatal("Must specify application name")
|
||||||
|
}
|
||||||
|
app := args[0]
|
||||||
|
*/
|
||||||
|
command := btypes.CommandStopProcess{}
|
||||||
|
for _, remote := range remotes {
|
||||||
|
response, err := StopProcess(privKey, remote, command)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%v failure. %v\n", remote, err)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%v success. %v\n", remote, response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cliListProcesses(c *cli.Context) {
|
||||||
|
/*
|
||||||
|
args := c.Args()
|
||||||
|
if len(args) == 0 {
|
||||||
|
log.Fatal("Must specify application name")
|
||||||
|
}
|
||||||
|
app := args[0]
|
||||||
|
*/
|
||||||
|
command := btypes.CommandListProcesses{}
|
||||||
|
for _, remote := range remotes {
|
||||||
|
response, err := ListProcesses(privKey, remote, command)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%v failure. %v\n", remote, err)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%v success: %v\n", remote, response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue