summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2014-03-19 17:01:57 -0700
committersersut <serdar@opscode.com>2014-03-19 17:42:58 -0700
commit41658bb4fbae8c1e54fe9bed1c6b0839e8b4e3e3 (patch)
treeaa1738792912ab2ead4a9731dc272a83dcd472f7 /lib
parent3328f4749faea190b4d5c17302aa83a6591f6305 (diff)
downloadchef-41658bb4fbae8c1e54fe9bed1c6b0839e8b4e3e3.tar.gz
Remove should_exit out of parameters and make ui.confirm less ugly.
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/knife/client_bulk_delete.rb2
-rw-r--r--lib/chef/knife/cookbook_bulk_delete.rb2
-rw-r--r--lib/chef/knife/core/ui.rb53
3 files changed, 40 insertions, 17 deletions
diff --git a/lib/chef/knife/client_bulk_delete.rb b/lib/chef/knife/client_bulk_delete.rb
index 1e1d6af190..f2be772759 100644
--- a/lib/chef/knife/client_bulk_delete.rb
+++ b/lib/chef/knife/client_bulk_delete.rb
@@ -71,7 +71,7 @@ class Chef
else
ui.msg("The following validators will be deleted:")
print_clients(validators)
- if ui.confirm("Are you sure you want to delete these validators", true, false)
+ if ui.confirm_without_exit("Are you sure you want to delete these validators")
destroy_clients(validators)
end
end
diff --git a/lib/chef/knife/cookbook_bulk_delete.rb b/lib/chef/knife/cookbook_bulk_delete.rb
index f8ad74d856..65fa888486 100644
--- a/lib/chef/knife/cookbook_bulk_delete.rb
+++ b/lib/chef/knife/cookbook_bulk_delete.rb
@@ -49,7 +49,7 @@ class Chef
ui.msg ""
unless config[:yes]
- ui.confirm("Do you really want to delete these cookbooks? (Y/N) ", false)
+ ui.confirm("Do you really want to delete these cookbooks")
if config[:purge]
ui.msg("Files that are common to multiple cookbooks are shared, so purging the files may break other cookbooks.")
diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb
index 5b86150fee..ff2545cfed 100644
--- a/lib/chef/knife/core/ui.rb
+++ b/lib/chef/knife/core/ui.rb
@@ -205,38 +205,61 @@ class Chef
output(format_for_display(object)) if config[:print_after]
end
- def confirm(question, append_instructions=true, default_choice=nil)
- return true if config[:yes]
-
+ def confirmation_instructions(default_choice)
case default_choice
- when 'Y', 'y'
- instructions = '? (Y/n)'
- when 'N', 'n'
- instructions = '? (y/N)'
+ when true
+ '? (Y/n)'
+ when false
+ '? (y/N)'
else
- instructions = '? (Y/N)'
+ '? (Y/N)'
end
+ end
+
+ # See confirm method for argument information
+ def confirm_without_exit(question, append_instructions=true, default_choice=nil)
+ return true if config[:yes]
stdout.print question
- stdout.print instructions if append_instructions
+ stdout.print confirmation_instructions(default_choice) if append_instructions
+
answer = stdin.readline
answer.chomp!
- answer == '' ? answer = default_choice : answer
+
case answer
when "Y", "y"
true
when "N", "n"
self.msg("You said no, so I'm done here.")
- if should_exit
- exit 3
+ false
+ when ""
+ unless default_choice.nil?
+ default_choice
else
- false
+ self.msg("I have no idea what to do with '#{answer}'")
+ self.msg("Just say Y or N, please.")
+ confirm_without_exit(question, append_instructions, default_choice)
end
else
- self.msg("I have no idea what to do with #{answer}")
+ self.msg("I have no idea what to do with '#{answer}'")
self.msg("Just say Y or N, please.")
- confirm(question)
+ confirm_without_exit(question, append_instructions, default_choice)
+ end
+ end
+
+ #
+ # Not the ideal signature for a function but we need to stick with this
+ # for now until we get a chance to break our API in Chef 12.
+ #
+ # question => Question to print before asking for confirmation
+ # append_instructions => Should print '? (Y/N)' as instructions
+ # default_choice => Set to true for 'Y', and false for 'N' as default answer
+ #
+ def confirm(question, append_instructions=true, default_choice=nil)
+ unless confirm_without_exit(question, append_instructions, default_choice)
+ exit 3
end
+ true
end
end