go-ethereum/internal/cli/account_new.go
Jerry a131e427f6 Automatically generate markdown pages from bor CLI
Adding a script that can automatically generate markdown pages from bor
CLI, so we can avoid copy-pasting helper strings whenever a flag is created,
deleted, or modified.

CLI docs could be generated with command `make docs`.
2022-05-09 17:10:36 +02:00

73 lines
1.6 KiB
Go

package cli
import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/internal/cli/flagset"
)
type AccountNewCommand struct {
*Meta
}
// MarkDown implements cli.MarkDown interface
func (a *AccountNewCommand) MarkDown() string {
items := []string{
"# Account new",
"The `account new` command creates a new local account file on the Bor data directory. Bor should not be running to execute this command.",
a.Flags().MarkDown(),
}
return strings.Join(items, "\n\n")
}
// Help implements the cli.Command interface
func (a *AccountNewCommand) Help() string {
return `Usage: bor account new
Create a new local account.
` + a.Flags().Help()
}
func (a *AccountNewCommand) Flags() *flagset.Flagset {
return a.NewFlagSet("account new")
}
// Synopsis implements the cli.Command interface
func (a *AccountNewCommand) Synopsis() string {
return "Create a new local account"
}
// Run implements the cli.Command interface
func (a *AccountNewCommand) Run(args []string) int {
flags := a.Flags()
if err := flags.Parse(args); err != nil {
a.UI.Error(err.Error())
return 1
}
keystore, err := a.GetKeystore()
if err != nil {
a.UI.Error(fmt.Sprintf("Failed to get keystore: %v", err))
return 1
}
password, err := a.AskPassword()
if err != nil {
a.UI.Error(err.Error())
return 1
}
account, err := keystore.NewAccount(password)
if err != nil {
a.UI.Error(fmt.Sprintf("Failed to create new account: %v", err))
return 1
}
a.UI.Output("\nYour new key was generated")
a.UI.Output(fmt.Sprintf("Public address of the key: %s", account.Address.Hex()))
a.UI.Output(fmt.Sprintf("Path of the secret key file: %s", account.URL.Path))
return 0
}