Skip to content
Snippets Groups Projects
Commit 16be7fd1 authored by Benjamin Bollen's avatar Benjamin Bollen
Browse files

further mold cobra and viper structure for e-db

parent 1e0aad92
No related branches found
No related tags found
No related merge requests found
......@@ -17,14 +17,16 @@
package commands
import (
"fmt"
// "fmt"
"os"
"strconv"
"strings"
cobra "github.com/spf13/cobra"
common "github.com/eris-ltd/common/go/common"
// common "github.com/eris-ltd/common/go/common"
defintion "github.com/eris-ltd/eris-db/defintions"
definitions "github.com/eris-ltd/eris-db/definitions"
version "github.com/eris-ltd/eris-db/version"
)
......@@ -34,8 +36,8 @@ const VERSION = version.VERSION
var do *definitions.Do
var ErisDbCmd = &cobra.Command {
Use: "eris-db"
Short: "Eris-DB is the beating heart of the eris chain."
Use: "eris-db",
Short: "Eris-DB is the beating heart of the eris chain.",
Long: `Eris-DB is the beating heart of the eris chain. Eris-DB combines
a modular consensus engine and application manager to run a chain to suit
your needs.
......@@ -44,7 +46,7 @@ Made with <3 by Eris Industries.
Complete documentation is available at https://docs.erisindustries.com
` + "\nVERSION:\n " + VERSION,
PersistentPreRun: func(cmd *cobra.Command, args [string]) {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// TODO: [ben] set up eris logger after glide resolution of logrus
},
Run: func(cmd *cobra.Command, args []string) { cmd.Help() },
......@@ -60,11 +62,12 @@ func Execute() {
func InitErisDb() {
// initialise an empty do struct for command execution
do = definitions.NowDo()
}
func AddCommands() {
buildServeCommand()
ErisDbCmd.AddCommand()
// name of the configuration file without extension
do.Config.SetConfigName("config")
do.Config.SetConfigType("yaml")
// look for configuration file in the working directory
do.Config.AddConfigPath(".")
// but let's move the location of the configuration to
}
func AddGlobalFlags() {
......@@ -73,6 +76,13 @@ func AddGlobalFlags() {
ErisDbCmd.PersistentFlags().BoolVarP(&do.Output, "output", "o", defaultOutput(), "should eris-db provide an output of its execution; default respects $ERIS_DB_OUTPUT")
}
func AddCommands() {
buildServeCommand()
ErisDbCmd.AddCommand(ServeCmd)
}
//------------------------------------------------------------------------------
// Defaults
......
......@@ -18,13 +18,13 @@ package commands
import (
"fmt"
"os"
// "os"
cobra "github.com/spf13/cobra"
common "github.com/eris-ltd/common/go/common"
// common "github.com/eris-ltd/common/go/common"
serve "github.com/eris-ltd/eris-db/serve"
// definitions "github.com/eris-ltd/eris-db/definitions"
)
var ServeCmd = &cobra.Command {
......@@ -36,15 +36,28 @@ manager. The client API can be disabled.`,
Example: `$ eris-db serve -- will start the Eris-DB node based on the configuration file in the current working directory,
$ eris-db serve myChainId --work-dir=/path/to/config -- will start the Eris-DB node based on the configuration file provided and assert the chain id matches.`,
PreRun: func(cmd *cobra.Command, args []string) {
fmt.Println("pre-run serving")
// TODO: [ben] log marmotty welcome
}
},
Run: func(cmd *cobra.Command, args []string) {
serve()
},
}
// build the serve subcommand
func buildServeCommand() {
addServeFlags()
}
func addServeFlags() {
fmt.Println("Adding Serve flags")
}
//------------------------------------------------------------------------------
// functions
func Serve(cmd *cobra.Command, args []string) {
func serve() {
fmt.Println("Served")
}
......@@ -16,20 +16,37 @@
package definitions
import (
viper "github.com/spf13/viper"
)
type Do struct {
Debug bool
Verbose bool
ChainId string
// Persistent flags not reflected in the configuration files
// only set through command line flags or environment variables
Debug bool // ERIS_DB_DEBUG
Verbose bool // ERIS_DB_VERBOSE
Output bool // ERIS_DB_OUTPUT
// Capital configuration options explicitly extracted from the Viper config
ChainId string // has to be set to non-empty string,
// uniquely identifying the chain.
// ChainType string
// CSV string
// AccountTypes []string
// Zip bool
// Tarball bool
Output bool
Config *viper.Viper
// Accounts []*Account
// Result string
}
func NowDo() *Do {
return &Do{}
do := new(Do)
do.Debug = false
do.Verbose = false
// the default value for output is set to true in cmd/eris-db.go;
// avoid double setting it here though
do.Output = false
do.ChainId = ""
do.Config = viper.New()
return do
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment