Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Bug 979992 - Only respond to 'y', 'yes', 'n', and 'no'
Browse files Browse the repository at this point in the history
Fix non-interactive stty behavior. Keep backwards compatibility of agree for anyone in non-interactive mode.  Also change "success" on app create to "done" to be consistent.
  • Loading branch information
smarterclayton committed Jul 9, 2013
1 parent b65753a commit 4d85213
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/rhc/commands/cartridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def add(cart_type)
rest_app = rest_client.find_application(options.namespace, options.app, :include => :cartridges)
rest_cartridge = rest_app.add_cartridge(cart)

success "Success"
success "done"

paragraph{ display_cart(rest_cartridge) }
paragraph{ rest_cartridge.messages.each { |msg| success msg } }
Expand Down
15 changes: 13 additions & 2 deletions lib/rhc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def certificate_file(file)
#

def interactive?
$stdout.tty? and not options.noprompt
$stdin.tty? and $stdout.tty? and not options.noprompt
end

def debug(*args)
Expand Down Expand Up @@ -242,9 +242,20 @@ def deprecated(msg,short = false)
warn "Warning: #{msg}\n" % ['a warning','an error',1]
end

#
# By default, agree should take a single character in interactive
#
def agree(*args, &block)
#args.push(interactive?.presence) if args.length == 1
block = lambda do |q|
q.validate = /\A(?:y|yes|n|no)\Z/i
end unless block_given?
super *args, &block
end

def confirm_action(question)
return if options.confirm
return if !options.noprompt && paragraph{ agree("#{question} (yes|no): ") }
return if !options.noprompt && paragraph{ agree "#{question} (yes|no): " }
raise RHC::ConfirmationError
end

Expand Down
16 changes: 14 additions & 2 deletions lib/rhc/highline_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class HighLineExtension < HighLine
end
end

if HighLine::CHARACTER_MODE == 'stty'
def raw_no_echo_mode
@state = `stty -g 2>/dev/null`
`stty raw -echo -icanon isig 2>&1`
end

def restore_mode
`stty #{@state} 2>&1`
end
end

def debug(msg)
$stderr.puts "DEBUG: #{msg}" if debug?
end
Expand All @@ -37,7 +48,7 @@ def say(msg)
statement = template.result(binding)

if @wrap_at
statement = statement.textwrap_ansi(@wrap_at, false)
statement = statement.chomp.textwrap_ansi(@wrap_at, false)
if @last_line_open && statement.length > 1
@last_line_open = false
@output.puts
Expand All @@ -52,7 +63,8 @@ def say(msg)
if statement[-1, 1] == " " or statement[-1, 1] == "\t"
@output.print(statement)
@output.flush
statement.strip_ansi.length + (@last_line_open || 0)
#statement.strip_ansi.length + (@last_line_open || 0)
true
else
@output.puts(statement)
false
Expand Down
2 changes: 1 addition & 1 deletion spec/rhc/commands/cartridge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def exit_with_code_and_message(code, message = nil)
run_output.should match(message) if message
end

def succeed_with_message(message = "Success")
def succeed_with_message(message = "done")
exit_with_code_and_message(0,message)
end

Expand Down

0 comments on commit 4d85213

Please sign in to comment.