Merge pull request #242 from cosmos/feature/move_to_examples

Move all binaries to examples
This commit is contained in:
Ethan Frey 2017-09-04 18:10:26 +02:00 committed by GitHub
commit c94500f269
40 changed files with 2347 additions and 146 deletions

1
.gitignore vendored
View File

@ -3,6 +3,5 @@ vendor
.vagrant .vagrant
merkleeyes.db merkleeyes.db
build build
shunit2
docs/guide/*.sh docs/guide/*.sh
keys/ keys/

View File

@ -3,6 +3,10 @@ GOTOOLS = github.com/mitchellh/gox \
github.com/rigelrozanski/shelldown/cmd/shelldown github.com/rigelrozanski/shelldown/cmd/shelldown
TUTORIALS=$(shell find docs/guide -name "*md" -type f) TUTORIALS=$(shell find docs/guide -name "*md" -type f)
EXAMPLES := counter eyes basecoin
INSTALL_EXAMPLES := $(addprefix install_,${EXAMPLES})
TEST_EXAMPLES := $(addprefix testex_,${EXAMPLES})
LINKER_FLAGS:="-X github.com/cosmos/cosmos-sdk/client/commands.CommitHash=`git rev-parse --short HEAD`" LINKER_FLAGS:="-X github.com/cosmos/cosmos-sdk/client/commands.CommitHash=`git rev-parse --short HEAD`"
all: get_vendor_deps install test all: get_vendor_deps install test
@ -10,9 +14,14 @@ all: get_vendor_deps install test
build: build:
@go build ./cmd/... @go build ./cmd/...
install: $(INSTALL_EXAMPLES): install_%:
cd ./examples/$* && make install
$(TEST_EXAMPLES): testex_%:
cd ./examples/$* && make test_cli
install: $(INSTALL_EXAMPLES)
@go install -ldflags $(LINKER_FLAGS) ./cmd/... @go install -ldflags $(LINKER_FLAGS) ./cmd/...
@go install -ldflags $(LINKER_FLAGS) ./docs/guide/counter/cmd/...
dist: dist:
@bash publish/dist.sh @bash publish/dist.sh
@ -26,35 +35,17 @@ test: test_unit test_cli
test_unit: test_unit:
@go test `glide novendor` @go test `glide novendor`
#go run tests/tendermint/*.go
test_cli: tests/cli/shunit2 test_cli: $(TEST_EXAMPLES)
# sudo apt-get install jq # sudo apt-get install jq
./tests/cli/keys.sh # wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2"
./tests/cli/rpc.sh
./tests/cli/init.sh
./tests/cli/basictx.sh
./tests/cli/eyes.sh
./tests/cli/roles.sh
./tests/cli/counter.sh
./tests/cli/restart.sh
./tests/cli/rest.sh
./tests/cli/ibc.sh
test_tutorial: docs/guide/shunit2 test_tutorial:
@shelldown ${TUTORIALS} @shelldown ${TUTORIALS}
@for script in docs/guide/*.sh ; do \ @for script in docs/guide/*.sh ; do \
bash $$script ; \ bash $$script ; \
done done
tests/cli/shunit2:
@wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2" \
-q -O tests/cli/shunit2
docs/guide/shunit2:
@wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2" \
-q -O docs/guide/shunit2
get_vendor_deps: tools get_vendor_deps: tools
@glide install @glide install

View File

@ -1,8 +0,0 @@
package commands
// import "github.com/cosmos/cosmos-sdk/plugins/ibc"
// // returns a new IBC plugin to be registered with Basecoin
// func NewIBCPlugin() *ibc.IBCPlugin {
// return ibc.New()
// }

View File

@ -1,43 +0,0 @@
package commands
import (
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tmlibs/cli"
tmflags "github.com/tendermint/tmlibs/cli/flags"
"github.com/tendermint/tmlibs/log"
)
//nolint
const (
defaultLogLevel = "error"
FlagLogLevel = "log_level"
)
var (
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
)
// RootCmd - main node command
var RootCmd = &cobra.Command{
Use: "basecoin",
Short: "A cryptocurrency framework in Golang based on Tendermint-Core",
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
level := viper.GetString(FlagLogLevel)
logger, err = tmflags.ParseLogLevel(level, logger, defaultLogLevel)
if err != nil {
return err
}
if viper.GetBool(cli.TraceFlag) {
logger = log.NewTracingLogger(logger)
}
return nil
},
}
func init() {
RootCmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level")
}

1067
docs/guide/shunit2 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
LINKER_FLAGS:="-X github.com/cosmos/cosmos-sdk/client/commands.CommitHash=`git rev-parse --short HEAD`"
install:
@go install -ldflags $(LINKER_FLAGS) ./cmd/...
test: test_unit test_cli
test_unit:
@go test `glide novendor`
test_cli:
./tests/cli/keys.sh
./tests/cli/rpc.sh
./tests/cli/init.sh
./tests/cli/basictx.sh
./tests/cli/roles.sh
./tests/cli/restart.sh
./tests/cli/rest.sh
./tests/cli/ibc.sh
.PHONY: install test test_unit test_cli

View File

@ -3,11 +3,11 @@ package main
import ( import (
"os" "os"
"github.com/spf13/cobra"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tmlibs/cli"
sdk "github.com/cosmos/cosmos-sdk" sdk "github.com/cosmos/cosmos-sdk"
client "github.com/cosmos/cosmos-sdk/client/commands" client "github.com/cosmos/cosmos-sdk/client/commands"
"github.com/cosmos/cosmos-sdk/cmd/basecoin/commands"
"github.com/cosmos/cosmos-sdk/modules/auth" "github.com/cosmos/cosmos-sdk/modules/auth"
"github.com/cosmos/cosmos-sdk/modules/base" "github.com/cosmos/cosmos-sdk/modules/base"
"github.com/cosmos/cosmos-sdk/modules/coin" "github.com/cosmos/cosmos-sdk/modules/coin"
@ -15,9 +15,16 @@ import (
"github.com/cosmos/cosmos-sdk/modules/ibc" "github.com/cosmos/cosmos-sdk/modules/ibc"
"github.com/cosmos/cosmos-sdk/modules/nonce" "github.com/cosmos/cosmos-sdk/modules/nonce"
"github.com/cosmos/cosmos-sdk/modules/roles" "github.com/cosmos/cosmos-sdk/modules/roles"
"github.com/cosmos/cosmos-sdk/server/commands"
"github.com/cosmos/cosmos-sdk/stack" "github.com/cosmos/cosmos-sdk/stack"
) )
// RootCmd is the entry point for this binary
var RootCmd = &cobra.Command{
Use: "basecoin",
Short: "A cryptocurrency framework in Golang based on Tendermint-Core",
}
// BuildApp constructs the stack we want to use for this app // BuildApp constructs the stack we want to use for this app
func BuildApp(feeDenom string) sdk.Handler { func BuildApp(feeDenom string) sdk.Handler {
return stack.New( return stack.New(
@ -42,19 +49,18 @@ func BuildApp(feeDenom string) sdk.Handler {
} }
func main() { func main() {
rt := commands.RootCmd
// require all fees in mycoin - change this in your app! // require all fees in mycoin - change this in your app!
commands.Handler = BuildApp("mycoin") commands.Handler = BuildApp("mycoin")
rt.AddCommand( RootCmd.AddCommand(
commands.InitCmd, commands.InitCmd,
commands.StartCmd, commands.StartCmd,
//commands.RelayCmd, //commands.RelayCmd,
commands.UnsafeResetAllCmd, commands.UnsafeResetAllCmd,
client.VersionCmd, client.VersionCmd,
) )
commands.SetUpRoot(RootCmd)
cmd := cli.PrepareMainCmd(rt, "BC", os.ExpandEnv("$HOME/.basecoin")) cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin"))
cmd.Execute() cmd.Execute()
} }

View File

@ -116,5 +116,7 @@ test03CreditTx() {
# Load common then run these tests with shunit2! # Load common then run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $DIR/shunit2
. $CLI_DIR/common.sh
. $CLI_DIR/shunit2

View File

@ -353,5 +353,7 @@ assertNewHeight() {
# Load common then run these tests with shunit2! # Load common then run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $DIR/shunit2
. $CLI_DIR/common.sh
. $CLI_DIR/shunit2

View File

@ -105,4 +105,6 @@ checkDir() {
# load and run these tests with shunit2! # load and run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/shunit2 CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $CLI_DIR/shunit2

View File

@ -26,4 +26,6 @@ testMakeKeys() {
# load and run these tests with shunit2! # load and run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/shunit2 CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $CLI_DIR/shunit2

View File

@ -17,6 +17,7 @@ oneTimeSetUp() {
baseserver serve --port $BPORT >/dev/null & baseserver serve --port $BPORT >/dev/null &
PID_PROXY=$! PID_PROXY=$!
disown disown
sleep 0.1 # for startup
} }
oneTimeTearDown() { oneTimeTearDown() {
@ -29,7 +30,8 @@ oneTimeTearDown() {
restAddr() { restAddr() {
assertNotNull "line=${LINENO}, keyname required" "$1" assertNotNull "line=${LINENO}, keyname required" "$1"
ADDR=$(curl ${URL}/keys/${1} 2>/dev/null | jq .address | tr -d \") ADDR=$(curl ${URL}/keys/${1} 2>/dev/null | jq .address | tr -d \")
assertNotEquals "line=${LINENO}, no key" "null" $ADDR assertNotEquals "line=${LINENO}, null key" "null" "$ADDR"
assertNotEquals "line=${LINENO}, no key" "" "$ADDR"
echo $ADDR echo $ADDR
} }
@ -49,13 +51,39 @@ restNoAccount() {
} }
test00GetAccount() { test00GetAccount() {
RECV=$(restAddr $POOR)
SENDER=$(restAddr $RICH)
restNoAccount $RECV
restAccount $SENDER "9007199254740992"
}
test01SendTx() {
SENDER=$(restAddr $RICH) SENDER=$(restAddr $RICH)
RECV=$(restAddr $POOR) RECV=$(restAddr $POOR)
restAccount $SENDER "9007199254740992" CMD="{\"from\": {\"app\": \"sigs\", \"addr\": \"$SENDER\"}, \"to\": {\"app\": \"sigs\", \"addr\": \"$RECV\"}, \"amount\": [{\"denom\": \"mycoin\", \"amount\": 992}], \"sequence\": 1}"
restNoAccount $RECV
UNSIGNED=$(curl -XPOST ${URL}/build/send -d "$CMD" 2>/dev/null)
if [ -n "$DEBUG" ]; then echo $UNSIGNED; echo; fi
TOSIGN="{\"name\": \"$RICH\", \"password\": \"qwertyuiop\", \"tx\": $UNSIGNED}"
SIGNED=$(curl -XPOST ${URL}/sign -d "$TOSIGN" 2>/dev/null)
TX=$(curl -XPOST ${URL}/tx -d "$SIGNED" 2>/dev/null)
if [ -n "$DEBUG" ]; then echo $TX; echo; fi
txSucceeded $? "$TX" "$RECV"
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
restAccount $SENDER "9007199254740000"
restAccount $RECV "992"
# Make sure tx is indexed
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
} }
# XXX Ex Usage: restCreateRole $PAYLOAD $EXPECTED # XXX Ex Usage: restCreateRole $PAYLOAD $EXPECTED
# Desc: Tests that the first returned signer.addr matches the expected # Desc: Tests that the first returned signer.addr matches the expected
restCreateRole() { restCreateRole() {
@ -86,30 +114,6 @@ test04CreateRoleInvalid() {
assertEquals "line=${LINENO}, should report validation failed" 0 $(echo $ERROR | grep "invalid hex" > /dev/null && echo 0 || echo 1) assertEquals "line=${LINENO}, should report validation failed" 0 $(echo $ERROR | grep "invalid hex" > /dev/null && echo 0 || echo 1)
} }
test01SendTx() {
SENDER=$(restAddr $RICH)
RECV=$(restAddr $POOR)
CMD="{\"from\": {\"app\": \"sigs\", \"addr\": \"$SENDER\"}, \"to\": {\"app\": \"sigs\", \"addr\": \"$RECV\"}, \"amount\": [{\"denom\": \"mycoin\", \"amount\": 992}], \"sequence\": 1}"
UNSIGNED=$(curl -XPOST ${URL}/build/send -d "$CMD" 2>/dev/null)
if [ -n "$DEBUG" ]; then echo $UNSIGNED; echo; fi
TOSIGN="{\"name\": \"$RICH\", \"password\": \"qwertyuiop\", \"tx\": $UNSIGNED}"
SIGNED=$(curl -XPOST ${URL}/sign -d "$TOSIGN" 2>/dev/null)
TX=$(curl -XPOST ${URL}/tx -d "$SIGNED" 2>/dev/null)
if [ -n "$DEBUG" ]; then echo $TX; echo; fi
txSucceeded $? "$TX" "$RECV"
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
restAccount $SENDER "9007199254740000"
restAccount $RECV "992"
# Make sure tx is indexed
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
}
# test02SendTxWithFee() { # test02SendTxWithFee() {
# SENDER=$(getAddr $RICH) # SENDER=$(getAddr $RICH)
@ -147,5 +151,7 @@ test01SendTx() {
# Load common then run these tests with shunit2! # Load common then run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $DIR/shunit2
. $CLI_DIR/common.sh
. $CLI_DIR/shunit2

View File

@ -78,6 +78,8 @@ test01OnRestart() {
# Load common then run these tests with shunit2! # Load common then run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $DIR/shunit2
. $CLI_DIR/common.sh
. $CLI_DIR/shunit2

View File

@ -90,5 +90,7 @@ test03SendMultiFromRole() {
# Load common then run these tests with shunit2! # Load common then run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $DIR/shunit2
. $CLI_DIR/common.sh
. $CLI_DIR/shunit2

View File

@ -127,4 +127,6 @@ test03Waiting() {
# load and run these tests with shunit2! # load and run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/shunit2 CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $CLI_DIR/shunit2

14
examples/counter/Makefile Normal file
View File

@ -0,0 +1,14 @@
LINKER_FLAGS:="-X github.com/cosmos/cosmos-sdk/client/commands.CommitHash=`git rev-parse --short HEAD`"
install:
@go install -ldflags $(LINKER_FLAGS) ./cmd/...
test: test_unit test_cli
test_unit:
@go test `glide novendor`
test_cli:
./tests/cli/counter.sh
.PHONY: install test test_unit test_cli

View File

@ -8,15 +8,17 @@ import (
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tmlibs/cli"
client "github.com/cosmos/cosmos-sdk/client/commands" client "github.com/cosmos/cosmos-sdk/client/commands"
"github.com/cosmos/cosmos-sdk/cmd/basecoin/commands" "github.com/cosmos/cosmos-sdk/examples/counter/plugins/counter"
"github.com/cosmos/cosmos-sdk/docs/guide/counter/plugins/counter" "github.com/cosmos/cosmos-sdk/server/commands"
) )
func main() { // RootCmd is the entry point for this binary
var RootCmd = &cobra.Command{ var RootCmd = &cobra.Command{
Use: "counter", Use: "counter",
Short: "demo plugin for basecoin", Short: "demo application for cosmos sdk",
} }
func main() {
// TODO: register the counter here // TODO: register the counter here
commands.Handler = counter.NewHandler("mycoin") commands.Handler = counter.NewHandler("mycoin")
@ -27,6 +29,7 @@ func main() {
commands.UnsafeResetAllCmd, commands.UnsafeResetAllCmd,
client.VersionCmd, client.VersionCmd,
) )
commands.SetUpRoot(RootCmd)
cmd := cli.PrepareMainCmd(RootCmd, "CT", os.ExpandEnv("$HOME/.counter")) cmd := cli.PrepareMainCmd(RootCmd, "CT", os.ExpandEnv("$HOME/.counter"))
cmd.Execute() cmd.Execute()

View File

@ -6,7 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk" sdk "github.com/cosmos/cosmos-sdk"
txcmd "github.com/cosmos/cosmos-sdk/client/commands/txs" txcmd "github.com/cosmos/cosmos-sdk/client/commands/txs"
"github.com/cosmos/cosmos-sdk/docs/guide/counter/plugins/counter" "github.com/cosmos/cosmos-sdk/examples/counter/plugins/counter"
"github.com/cosmos/cosmos-sdk/modules/coin" "github.com/cosmos/cosmos-sdk/modules/coin"
) )

View File

@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/commands" "github.com/cosmos/cosmos-sdk/client/commands"
"github.com/cosmos/cosmos-sdk/client/commands/query" "github.com/cosmos/cosmos-sdk/client/commands/query"
"github.com/cosmos/cosmos-sdk/docs/guide/counter/plugins/counter" "github.com/cosmos/cosmos-sdk/examples/counter/plugins/counter"
"github.com/cosmos/cosmos-sdk/stack" "github.com/cosmos/cosmos-sdk/stack"
) )

View File

@ -14,7 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/commands/seeds" "github.com/cosmos/cosmos-sdk/client/commands/seeds"
txcmd "github.com/cosmos/cosmos-sdk/client/commands/txs" txcmd "github.com/cosmos/cosmos-sdk/client/commands/txs"
bcount "github.com/cosmos/cosmos-sdk/docs/guide/counter/cmd/countercli/commands" bcount "github.com/cosmos/cosmos-sdk/examples/counter/cmd/countercli/commands"
authcmd "github.com/cosmos/cosmos-sdk/modules/auth/commands" authcmd "github.com/cosmos/cosmos-sdk/modules/auth/commands"
basecmd "github.com/cosmos/cosmos-sdk/modules/base/commands" basecmd "github.com/cosmos/cosmos-sdk/modules/base/commands"
coincmd "github.com/cosmos/cosmos-sdk/modules/coin/commands" coincmd "github.com/cosmos/cosmos-sdk/modules/coin/commands"

View File

@ -112,5 +112,7 @@ test03AddCount() {
# Load common then run these tests with shunit2! # Load common then run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $DIR/shunit2
. $CLI_DIR/common.sh
. $CLI_DIR/shunit2

14
examples/eyes/Makefile Normal file
View File

@ -0,0 +1,14 @@
LINKER_FLAGS:="-X github.com/cosmos/cosmos-sdk/client/commands.CommitHash=`git rev-parse --short HEAD`"
install:
@go install -ldflags $(LINKER_FLAGS) ./cmd/...
test: test_unit test_cli
test_unit:
@go test `glide novendor`
test_cli:
./tests/cli/eyes.sh
.PHONY: install test test_unit test_cli

View File

@ -8,7 +8,7 @@ import (
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/cosmos/cosmos-sdk/cmd/basecoin/commands" "github.com/cosmos/cosmos-sdk/server/commands"
) )
// InitCmd - node initialization command // InitCmd - node initialization command

View File

@ -3,16 +3,24 @@ package main
import ( import (
"os" "os"
"github.com/spf13/cobra"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tmlibs/cli"
sdk "github.com/cosmos/cosmos-sdk" sdk "github.com/cosmos/cosmos-sdk"
client "github.com/cosmos/cosmos-sdk/client/commands" client "github.com/cosmos/cosmos-sdk/client/commands"
"github.com/cosmos/cosmos-sdk/cmd/basecoin/commands"
"github.com/cosmos/cosmos-sdk/modules/base" "github.com/cosmos/cosmos-sdk/modules/base"
"github.com/cosmos/cosmos-sdk/modules/eyes" "github.com/cosmos/cosmos-sdk/modules/eyes"
"github.com/cosmos/cosmos-sdk/server/commands"
"github.com/cosmos/cosmos-sdk/stack" "github.com/cosmos/cosmos-sdk/stack"
) )
// RootCmd is the entry point for this binary
var RootCmd = &cobra.Command{
Use: "eyes",
Short: "key-value store",
Long: "A demo app to show key-value store with proofs over abci",
}
// BuildApp constructs the stack we want to use for this app // BuildApp constructs the stack we want to use for this app
func BuildApp() sdk.Handler { func BuildApp() sdk.Handler {
return stack.New( return stack.New(
@ -26,20 +34,17 @@ func BuildApp() sdk.Handler {
} }
func main() { func main() {
rt := commands.RootCmd
rt.Short = "eyes"
rt.Long = "A demo app to show key-value store with proofs over abci"
commands.Handler = BuildApp() commands.Handler = BuildApp()
rt.AddCommand( RootCmd.AddCommand(
// out own init command to not require argument // out own init command to not require argument
InitCmd, InitCmd,
commands.StartCmd, commands.StartCmd,
commands.UnsafeResetAllCmd, commands.UnsafeResetAllCmd,
client.VersionCmd, client.VersionCmd,
) )
commands.SetUpRoot(RootCmd)
cmd := cli.PrepareMainCmd(rt, "EYE", os.ExpandEnv("$HOME/.eyes")) cmd := cli.PrepareMainCmd(RootCmd, "EYE", os.ExpandEnv("$HOME/.eyes"))
cmd.Execute() cmd.Execute()
} }

View File

@ -66,6 +66,8 @@ test00SetGetRemove() {
# Load common then run these tests with shunit2! # Load common then run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
. $DIR/shunit2
. $CLI_DIR/common.sh
. $CLI_DIR/shunit2

View File

@ -18,7 +18,7 @@ import (
// InitCmd - node initialization command // InitCmd - node initialization command
var InitCmd = &cobra.Command{ var InitCmd = &cobra.Command{
Use: "init [address]", Use: "init [address]",
Short: "Initialize a basecoin blockchain", Short: "Initialize genesis files for a blockchain",
RunE: initCmd, RunE: initCmd,
} }

41
server/commands/root.go Normal file
View File

@ -0,0 +1,41 @@
package commands
import (
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tmlibs/cli"
tmflags "github.com/tendermint/tmlibs/cli/flags"
"github.com/tendermint/tmlibs/log"
)
//nolint
const (
defaultLogLevel = "error"
FlagLogLevel = "log_level"
)
var (
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
)
// preRunSetup should be set as PersistentPreRunE on the root command to
// properly handle the logging and the tracer
func preRunSetup(cmd *cobra.Command, args []string) (err error) {
level := viper.GetString(FlagLogLevel)
logger, err = tmflags.ParseLogLevel(level, logger, defaultLogLevel)
if err != nil {
return err
}
if viper.GetBool(cli.TraceFlag) {
logger = log.NewTracingLogger(logger)
}
return nil
}
func SetUpRoot(cmd *cobra.Command) {
cmd.PersistentPreRunE = preRunSetup
cmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level")
}

View File

@ -9,8 +9,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/tendermint/abci/server"
sdk "github.com/cosmos/cosmos-sdk" sdk "github.com/cosmos/cosmos-sdk"
"github.com/tendermint/abci/server"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tmlibs/cli"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
@ -22,10 +22,10 @@ import (
"github.com/cosmos/cosmos-sdk/app" "github.com/cosmos/cosmos-sdk/app"
) )
// StartCmd - command to start running the basecoin node! // StartCmd - command to start running the abci app (and tendermint)!
var StartCmd = &cobra.Command{ var StartCmd = &cobra.Command{
Use: "start", Use: "start",
Short: "Start basecoin", Short: "Start this full node",
RunE: startCmd, RunE: startCmd,
} }
@ -47,7 +47,7 @@ var (
func init() { func init() {
flags := StartCmd.Flags() flags := StartCmd.Flags()
flags.String(FlagAddress, "tcp://0.0.0.0:46658", "Listen address") flags.String(FlagAddress, "tcp://0.0.0.0:46658", "Listen address")
flags.Bool(FlagWithoutTendermint, false, "Only run basecoin abci app, assume external tendermint process") flags.Bool(FlagWithoutTendermint, false, "Only run abci app, assume external tendermint process")
// add all standard 'tendermint node' flags // add all standard 'tendermint node' flags
tcmd.AddNodeFlags(StartCmd) tcmd.AddNodeFlags(StartCmd)
} }

1067
tests/cli/shunit2 Normal file

File diff suppressed because it is too large Load Diff