Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Cobra CLI #64

Merged
merged 13 commits into from
Apr 21, 2017
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.4.0 (TBD)

BREAKING CHANGES:

- CLI now uses Cobra, which forced changes to some of the flag names and orderings

IMPROVEMENTS:

- `basecoin init` doesn't generate error if already initialized

## 0.3.1 (March 23, 2017)

IMPROVEMENTS:
Expand Down
12 changes: 6 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (
"strings"

abci "github.com/tendermint/abci/types"
sm "github.com/tendermint/basecoin/state"
"github.com/tendermint/basecoin/types"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-wire"
eyes "github.com/tendermint/merkleeyes/client"

sm "github.com/tendermint/basecoin/state"
"github.com/tendermint/basecoin/types"
"github.com/tendermint/basecoin/version"
)

const (
version = "0.1"
maxTxSize = 10240

maxTxSize = 10240
PluginNameBase = "base"
)

Expand Down Expand Up @@ -44,7 +44,7 @@ func (app *Basecoin) GetState() *sm.State {

// ABCI::Info
func (app *Basecoin) Info() abci.ResponseInfo {
return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version)}
return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version.Version)}
}

func (app *Basecoin) RegisterPlugin(plugin types.Plugin) {
Expand Down
27 changes: 26 additions & 1 deletion app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package app

import (
"encoding/hex"
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cmn "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
eyescli "github.com/tendermint/merkleeyes/client"
)

const genesisFilepath = "./testdata/genesis.json"

func TestLoadGenesis(t *testing.T) {
assert, require := assert.New(t), require.New(t)

eyesCli := eyescli.NewLocalClient("", 0)
app := NewBasecoin(eyesCli)
err := app.LoadGenesis("./testdata/genesis.json")
err := app.LoadGenesis(genesisFilepath)
require.Nil(err, "%+v", err)

// check the chain id
Expand All @@ -41,3 +45,24 @@ func TestLoadGenesis(t *testing.T) {
assert.EqualValues(pkbyte, epk[:])
}
}

func TestParseGenesisList(t *testing.T) {
assert, require := assert.New(t), require.New(t)

bytes, err := cmn.ReadFile(genesisFilepath)
require.Nil(err, "loading genesis file %+v", err)

// the basecoin genesis go-data :)
genDoc := new(FullGenesisDoc)
err = json.Unmarshal(bytes, genDoc)
require.Nil(err, "unmarshaling genesis file %+v", err)

pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions)
require.Nil(err, "%+v", err)
genDoc.AppOptions.pluginOptions = pluginOpts

assert.Equal(genDoc.AppOptions.pluginOptions[0].Key, "plugin1/key1")
assert.Equal(genDoc.AppOptions.pluginOptions[1].Key, "plugin1/key2")
assert.Equal(genDoc.AppOptions.pluginOptions[0].Value, "value1")
assert.Equal(genDoc.AppOptions.pluginOptions[1].Value, "value2")
}
26 changes: 11 additions & 15 deletions cmd/basecoin/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package main

import (
"fmt"
"os"
"github.com/spf13/cobra"

"github.com/tendermint/basecoin/cmd/commands"
"github.com/tendermint/basecoin/version"
"github.com/urfave/cli"
)

func main() {
app := cli.NewApp()
app.Name = "basecoin"
app.Usage = "basecoin [command] [args...]"
app.Version = version.Version
app.Commands = []cli.Command{
var RootCmd = &cobra.Command{
Use: "basecoin",
Short: "A cryptocurrency framework in Golang based on Tendermint-Core",
}

RootCmd.AddCommand(
commands.InitCmd,
commands.StartCmd,
commands.TxCmd,
Expand All @@ -24,10 +22,8 @@ func main() {
commands.BlockCmd,
commands.AccountCmd,
commands.UnsafeResetAllCmd,
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
commands.VersionCmd,
)

commands.ExecuteWithDebug(RootCmd)
}
119 changes: 0 additions & 119 deletions cmd/commands/flags.go

This file was deleted.

Loading