Skip to content

Commit

Permalink
Add dry-run mode to update command (#90)
Browse files Browse the repository at this point in the history
* Add dry-run mode to update command

Fixes #83

* Update cmd/update.go

Co-authored-by: Lucas Bremgartner <breml@users.noreply.github.com>

* Return status code 3 for dry-run updates

I'm using 3 because 2 is generally reserved for special meanings.
Ref: https://tldp.org/LDP/abs/html/exitcodes.html

Co-authored-by: Lucas Bremgartner <breml@users.noreply.github.com>
  • Loading branch information
marcosnils and breml authored Apr 1, 2021
1 parent db36861 commit 192528b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import (
)

type updateCmd struct {
cmd *cobra.Command
cmd *cobra.Command
opts updateOpts
}

type updateOpts struct {
dryRun bool
}

type updateInfo struct{ version, url string }
Expand Down Expand Up @@ -75,6 +80,10 @@ func newUpdateCmd() *updateCmd {
return nil
}

if root.opts.dryRun {
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] ")
Expand Down Expand Up @@ -129,6 +138,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")
return root
}

Expand Down

0 comments on commit 192528b

Please sign in to comment.