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

Add -y flag to oasis wallet remove #217

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/account/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ var (
func init() {
entityInitCmd.Flags().StringVarP(&entityOutputFile, "output-file", "o", "", "output entity descriptor into specified JSON file")
entityInitCmd.Flags().AddFlagSet(common.AccountFlag)
entityInitCmd.Flags().AddFlagSet(common.YesFlag)
entityInitCmd.Flags().AddFlagSet(common.AnswerYesFlag)

entityRegisterCmd.Flags().AddFlagSet(common.SelectorNAFlags)
entityRegisterCmd.Flags().AddFlagSet(common.TxFlags)
Expand All @@ -251,7 +251,7 @@ func init() {

entityMetadataUpdateCmd.Flags().StringVarP(&registryPath, "registry-dir", "r", "", "path to the metadata registry directory")
entityMetadataUpdateCmd.Flags().AddFlagSet(common.AccountFlag)
entityMetadataUpdateCmd.Flags().AddFlagSet(common.YesFlag)
entityMetadataUpdateCmd.Flags().AddFlagSet(common.AnswerYesFlag)

entityCmd.AddCommand(entityInitCmd)
entityCmd.AddCommand(entityRegisterCmd)
Expand Down
12 changes: 12 additions & 0 deletions cmd/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var (
selectedHeight int64
force bool
answerYes bool
)

// HeightFlag is the flag for specifying block height.
Expand All @@ -20,6 +21,9 @@ var HeightFlag *flag.FlagSet
// ForceFlag is a force mode switch.
var ForceFlag *flag.FlagSet

// AnswerYesFlag answers yes to all questions.
var AnswerYesFlag *flag.FlagSet

// GetHeight returns the user-selected block height.
func GetHeight() int64 {
return selectedHeight
Expand All @@ -30,6 +34,11 @@ func IsForce() bool {
return force
}

// IsForce returns force mode.
func GetAnswerYes() bool {
return answerYes
}

// GetActualHeight returns the user-selected block height if explicitly
// specified, or the current latest height.
func GetActualHeight(
Expand All @@ -53,4 +62,7 @@ func init() {

ForceFlag = flag.NewFlagSet("", flag.ContinueOnError)
ForceFlag.BoolVarP(&force, "force", "f", false, "treat safety check errors as warnings")

AnswerYesFlag = flag.NewFlagSet("", flag.ContinueOnError)
AnswerYesFlag.BoolVarP(&answerYes, "yes", "y", false, "answer yes to all questions")
}
2 changes: 1 addition & 1 deletion cmd/common/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (

// Confirm asks the user for confirmation and aborts when rejected.
func Confirm(msg, abortMsg string) {
if txYes {
if answerYes {
fmt.Printf("? %s Yes\n", msg)
return
}
Expand Down
11 changes: 2 additions & 9 deletions cmd/common/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var (
txGasPrice string
txFeeDenom string
txEncrypted bool
txYes bool
txUnsigned bool
txFormat string
txOutputFile string
Expand All @@ -51,9 +50,6 @@ const (
)

var (
// YesFlag corresponds to the yes-to-all flag.
YesFlag *flag.FlagSet

// TxFlags contains the common consensus transaction flags.
TxFlags *flag.FlagSet

Expand Down Expand Up @@ -572,17 +568,14 @@ func WaitForEvent(
}

func init() {
YesFlag = flag.NewFlagSet("", flag.ContinueOnError)
YesFlag.BoolVarP(&txYes, "yes", "y", false, "answer yes to all questions")

RuntimeTxFlags = flag.NewFlagSet("", flag.ContinueOnError)
RuntimeTxFlags.BoolVar(&txOffline, "offline", false, "do not perform any operations requiring network access")
RuntimeTxFlags.Uint64Var(&txNonce, "nonce", invalidNonce, "override nonce to use")
RuntimeTxFlags.Uint64Var(&txGasLimit, "gas-limit", invalidGasLimit, "override gas limit to use (disable estimation)")
RuntimeTxFlags.StringVar(&txGasPrice, "gas-price", "", "override gas price to use")
RuntimeTxFlags.StringVar(&txFeeDenom, "fee-denom", "", "override fee denomination (defaults to native)")
RuntimeTxFlags.BoolVar(&txEncrypted, "encrypted", false, "encrypt transaction call data (requires online mode)")
RuntimeTxFlags.AddFlagSet(YesFlag)
RuntimeTxFlags.AddFlagSet(AnswerYesFlag)
RuntimeTxFlags.BoolVar(&txUnsigned, "unsigned", false, "do not sign transaction")
RuntimeTxFlags.StringVar(&txFormat, "format", "json", "transaction output format (for offline/unsigned modes) [json, cbor]")
RuntimeTxFlags.StringVarP(&txOutputFile, "output-file", "o", "", "output transaction into specified file instead of broadcasting")
Expand All @@ -592,7 +585,7 @@ func init() {
TxFlags.Uint64Var(&txNonce, "nonce", invalidNonce, "override nonce to use")
TxFlags.Uint64Var(&txGasLimit, "gas-limit", invalidGasLimit, "override gas limit to use (disable estimation)")
TxFlags.StringVar(&txGasPrice, "gas-price", "", "override gas price to use")
TxFlags.AddFlagSet(YesFlag)
TxFlags.AddFlagSet(AnswerYesFlag)
TxFlags.BoolVar(&txUnsigned, "unsigned", false, "do not sign transaction")
TxFlags.StringVar(&txFormat, "format", "json", "transaction output format (for offline/unsigned modes) [json, cbor]")
TxFlags.StringVarP(&txOutputFile, "output-file", "o", "", "output transaction into specified file instead of broadcasting")
Expand Down
2 changes: 1 addition & 1 deletion cmd/common/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func LoadAccount(cfg *config.Config, name string) wallet.Account {
cobra.CheckErr(err)

var passphrase string
if af.RequiresPassphrase() && !txYes {
if af.RequiresPassphrase() && !answerYes {
// Ask for passphrase to decrypt the account.
fmt.Printf("Unlock your account.\n")

Expand Down
35 changes: 21 additions & 14 deletions cmd/wallet/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"

"github.com/oasisprotocol/cli/cmd/common"
"github.com/oasisprotocol/cli/config"
)

Expand All @@ -23,25 +24,31 @@ var rmCmd = &cobra.Command{
cobra.CheckErr(fmt.Errorf("account '%s' does not exist", name))
}

fmt.Printf("WARNING: Removing the account will ERASE secret key material!\n")
fmt.Printf("WARNING: THIS ACTION IS IRREVERSIBLE!\n")

var result string
confirmText := fmt.Sprintf("I really want to remove account %s", name)
prompt := &survey.Input{
Message: fmt.Sprintf("Enter '%s' (without quotes) to confirm removal:", confirmText),
}
err := survey.AskOne(prompt, &result)
cobra.CheckErr(err)

if result != confirmText {
cobra.CheckErr("Aborted.")
if !common.GetAnswerYes() {
fmt.Printf("WARNING: Removing the account will ERASE secret key material!\n")
fmt.Printf("WARNING: THIS ACTION IS IRREVERSIBLE!\n")

var result string
confirmText := fmt.Sprintf("I really want to remove account %s", name)
prompt := &survey.Input{
Message: fmt.Sprintf("Enter '%s' (without quotes) to confirm removal:", confirmText),
}
err := survey.AskOne(prompt, &result)
cobra.CheckErr(err)

if result != confirmText {
cobra.CheckErr("Aborted.")
}
}

err = cfg.Wallet.Remove(name)
err := cfg.Wallet.Remove(name)
cobra.CheckErr(err)

err = cfg.Save()
cobra.CheckErr(err)
},
}

func init() {
rmCmd.Flags().AddFlagSet(common.AnswerYesFlag)
}
5 changes: 5 additions & 0 deletions docs/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ logan ledger (ed25519-legacy:0) oasis1qpl4axynedmdrrgrg7dpw3yxc4
oscar (*) file (ed25519-raw) oasis1qp87hflmelnpqhzcqcw8rhzakq4elj7jzv090p3e
```

You can also delete accounct in non-interactive mode format by passing the
`-y` parameter:

![code shell](../examples/wallet/remove-y.in.static)

## Set Default Account {#set-default}

To change your default account, use `wallet set-default <name>` and the
Expand Down
2 changes: 1 addition & 1 deletion examples/transaction/sign.y.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Method: staking.Transfer
Body:
To: oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx
Amount: 1.0 TEST
Nonce: 43
Nonce: 45
Fee:
Amount: 0.0 TEST
Gas limit: 1265
Expand Down
1 change: 1 addition & 0 deletions examples/wallet/remove-y.in.static
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oasis wallet remove lenny -y
Empty file.
Loading