Skip to content

Commit

Permalink
Force flag for no confirm prompt #80 #81
Browse files Browse the repository at this point in the history
  • Loading branch information
simcap committed Mar 21, 2017
1 parent fb4248d commit bfafca2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Rudimentary security groups port scanner inspector via `awless inspect -i port_scanner`
- Template: compile time check of undefined or unused references
- [#78](https://github.com/wallix/awless/issues/78): Show progress when uploadgin object to storage
- [#81](https://github.com/wallix/awless/issues/81): Global force flag `--force` to bypass confirm prompt

### Bugfixes

Expand Down
4 changes: 3 additions & 1 deletion commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
verboseGlobalFlag bool
extraVerboseGlobalFlag bool
localGlobalFlag bool
forceGlobalFlag bool
versionGlobalFlag bool
awsRegionGlobalFlag string
awsProfileGlobalFlag string
Expand All @@ -38,7 +39,8 @@ var (
func init() {
RootCmd.PersistentFlags().BoolVarP(&verboseGlobalFlag, "verbose", "v", false, "Turn on verbose mode for all commands")
RootCmd.PersistentFlags().BoolVarP(&extraVerboseGlobalFlag, "extra-verbose", "e", false, "Turn on extra verbose mode (including regular verbose) for all commands")
RootCmd.PersistentFlags().BoolVar(&localGlobalFlag, "local", false, "Work offline only with synced/local resources")
RootCmd.PersistentFlags().BoolVarP(&localGlobalFlag, "local", "l", false, "Work offline only with synced/local resources")
RootCmd.PersistentFlags().BoolVarP(&forceGlobalFlag, "force", "f", false, "Force the command and bypass any confirmation prompt")
RootCmd.PersistentFlags().StringVar(&awsRegionGlobalFlag, "aws-region", "", "Overwrite AWS region")
RootCmd.PersistentFlags().StringVar(&awsProfileGlobalFlag, "aws-profile", "", "Overwrite AWS profile")
RootCmd.Flags().BoolVar(&versionGlobalFlag, "version", false, "Print awless version")
Expand Down
14 changes: 9 additions & 5 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,17 @@ func runTemplate(templ *template.Template, fillers ...map[string]interface{}) er
_, err = templ.Compile(awsDriver)
exitOn(err)

fmt.Println()
fmt.Printf("%s\n", renderGreenFn(templ))
fmt.Println()
fmt.Print("Confirm? (y/n): ")

var yesorno string
_, err = fmt.Scanln(&yesorno)
exitOn(err)
if forceGlobalFlag {
yesorno = "y"
} else {
fmt.Println()
fmt.Print("Confirm? (y/n): ")
_, err = fmt.Scanln(&yesorno)
exitOn(err)
}

if strings.TrimSpace(yesorno) == "y" {
newTempl, err := templ.Run(awsDriver)
Expand Down

0 comments on commit bfafca2

Please sign in to comment.