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

go-kosu: make init a subcommand instead of a flag #191

Merged
merged 3 commits into from Jul 30, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

make init a subcommand instead of flag

  • Loading branch information
hrharder committed Jul 26, 2019
commit b716f65fb7f3838c0486c0ed2f31cae5ebff61ba
@@ -88,36 +88,44 @@ func main() {
key []byte
)

cobra.OnInitialize(func() {
cfg.Home = expandPath(cfg.Home)
})

rootCmd := &cobra.Command{
Use: "kosud",
Short: "Starts the kosu node",
Long: "Main entrypoint for Kosu validators and full nodes.\nPrior to use, 'kosud init' must be run.",
Run: func(cmd *cobra.Command, args []string) {
if err := run(&cfg, key); err != nil {
var err error
key, err = abci.LoadPrivateKey(cfg.Home)
if err != nil {
stdlog.Fatal(err)
}

if err = run(&cfg, key); err != nil {
stdlog.Fatal(err)
}
},
}
rootCmd.PersistentFlags().StringVar(&cfg.Home, "home", "~/.kosu", "directory for config and data")
rootCmd.PersistentFlags().BoolVar(&cfg.Debug, "debug", false, "enable debuging")
rootCmd.Flags().StringVar(&cfg.Web3, "web3", "wss://ethnet.zaidan.io/ws/kosu", "web3 provider URL")
rootCmd.Flags().BoolVar(&cfg.Init, "init", false, "initializes directory like 'tendermint init' does")

cobra.OnInitialize(func() {
cfg.Home = expandPath(cfg.Home)
if cfg.Init {
initCmd := &cobra.Command{
Use: "init",
Short: "Initialize a home directory and configuration",
Long: "Generates a Tendermint configuration directory and key pair for a Kosu node.\nThe default home directory is '$HOME/.kosu', which can be overridden with the '--home' flag.",
Run: func(cmd *cobra.Command, args []string) {
if err := abci.InitTendermint(cfg.Home); err != nil {
stdlog.Fatal(err)
}
}
},
}

var err error
key, err = abci.LoadPrivateKey(cfg.Home)
if err != nil {
stdlog.Fatal(err)
}
})
rootCmd.PersistentFlags().StringVarP(&cfg.Home, "home", "H", "~/.kosu", "directory for config and data")
rootCmd.PersistentFlags().BoolVarP(&cfg.Debug, "debug", "d", false, "enable debuging")
rootCmd.Flags().StringVarP(&cfg.Web3, "web3", "E", "ws://localhost:8546", "URL of a WebSocket Ethereum JSONRPC provider")

rootCmd.AddCommand(rpc.NewCommand())
rootCmd.AddCommand(initCmd)

if err := rootCmd.Execute(); err != nil {
stdlog.Fatal(err)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.