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 force flag for update #101

Merged
merged 5 commits into from
Jun 23, 2021
Merged
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
39 changes: 21 additions & 18 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package cmd
import (
"bufio"
"fmt"
"os"
"strings"

"github.com/apex/log"
"github.com/fatih/color"
"github.com/hashicorp/go-version"
"github.com/marcosnils/bin/pkg/config"
"github.com/marcosnils/bin/pkg/providers"
"github.com/spf13/cobra"
"os"
"strings"
)

type updateCmd struct {
Expand All @@ -20,8 +19,9 @@ type updateCmd struct {
}

type updateOpts struct {
dryRun bool
all bool
yesToUpdate bool
dryRun bool
all bool
}

type updateInfo struct{ version, url string }
Expand Down Expand Up @@ -84,21 +84,23 @@ func newUpdateCmd() *updateCmd {
return wrapErrorWithCode(fmt.Errorf("Updates found, exit (dry-run mode)."), 3, "")
}

// TODO will have to refactor this prompt to a separate function
// so it can be reused in some other places
fmt.Printf("\nDo you want to continue? [Y/n] ")
reader := bufio.NewReader(os.Stdin)
var response string
if !root.opts.yesToUpdate {
// TODO will have to refactor this prompt to a separate function
// so it can be reused in some other places
fmt.Printf("\nDo you want to continue? [Y/n] ")
reader := bufio.NewReader(os.Stdin)
var response string

response, err := reader.ReadString('\n')
if err != nil {
return fmt.Errorf("Invalid input")
}
response, err := reader.ReadString('\n')
sascha-andres marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("Invalid input")
}

switch strings.ToLower(strings.TrimSpace(response)) {
case "y", "yes":
default:
return fmt.Errorf("Command aborted")
switch strings.ToLower(strings.TrimSpace(response)) {
case "y", "yes":
default:
return fmt.Errorf("Command aborted")
}
}

// TODO :S code smell here, this pretty much does
Expand Down Expand Up @@ -139,6 +141,7 @@ func newUpdateCmd() *updateCmd {

root.cmd = cmd
root.cmd.Flags().BoolVarP(&root.opts.dryRun, "dry-run", "", false, "Only show status, don't prompt for update")
root.cmd.Flags().BoolVarP(&root.opts.yesToUpdate, "yes", "y", false, "Assume yes to update prompt")
root.cmd.Flags().BoolVarP(&root.opts.all, "all", "a", false, "Show all possible download options (skip scoring & filtering)")
return root
}
Expand Down