Skip to content

Commit

Permalink
Prompt for delete CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
kompotkot committed Oct 9, 2024
1 parent 9536715 commit df9c8ce
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -864,6 +865,7 @@ func CreateDatabaseOperationCommand() *cobra.Command {
createJobsCommand.Flags().Uint64Var(&deployBlock, "deploy-block", 0, "The block number to deploy contract (default: 0)")

var jobIds, jobAddresses, jobCustomerIds []string
var silentFlag bool

deleteJobsCommand := &cobra.Command{
Use: "delete-jobs",
Expand Down Expand Up @@ -903,6 +905,25 @@ func CreateDatabaseOperationCommand() *cobra.Command {
fmt.Printf("- %s - %d jobs\n", k, v)
}

output := "no"
if silentFlag {
output = "yes"
} else {
var promptErr error
output, promptErr = StringPrompt("Continue? (y/yes)")
if promptErr != nil {
return promptErr
}
}

switch output {
case "y":
case "yes":
default:
fmt.Println("Canceled")
return nil
}

deleteJobsErr := indexer.DBConnection.DeleteJobs(jobIds)
if deleteJobsErr != nil {
return deleteJobsErr
Expand All @@ -916,6 +937,7 @@ func CreateDatabaseOperationCommand() *cobra.Command {
deleteJobsCommand.Flags().StringSliceVar(&jobIds, "job-ids", []string{}, "The list of job UUIDs separated by coma")
deleteJobsCommand.Flags().StringSliceVar(&jobAddresses, "addresses", []string{}, "The list of addresses created jobs for separated by coma")
deleteJobsCommand.Flags().StringSliceVar(&jobCustomerIds, "customer-ids", []string{}, "The list of customer IDs created jobs for separated by coma")
deleteJobsCommand.Flags().BoolVar(&silentFlag, "silent", false, "Set this flag to run command without prompt")

indexCommand.AddCommand(deploymentBlocksCommand)
indexCommand.AddCommand(createJobsCommand)
Expand Down Expand Up @@ -1214,3 +1236,17 @@ func CreateEVMGenerateCommand() *cobra.Command {

return evmGenerateCmd
}

func StringPrompt(label string) (string, error) {
var output string
r := bufio.NewReader(os.Stdin)

fmt.Fprint(os.Stderr, label+" ")
var readErr error
output, readErr = r.ReadString('\n')
if readErr != nil {
return "", readErr
}

return strings.TrimSpace(output), nil
}

0 comments on commit df9c8ce

Please sign in to comment.