Module: Reap::Utilities::ShellUtils
Instance Attribute Summary
Attributes included from OptionUtils
#dryrun, #force, #trace, #verbose
Instance Method Summary collapse
-
#ask(question, answers = nil) ⇒ Object
Convenient method to get simple console reply.
-
#password(prompt = nil) ⇒ Object
Ask for a password.
-
#sh(cmd) ⇒ Object
Shell runner.
-
#status(message) ⇒ Object
Internal status report.
Methods included from OptionUtils
#dryrun?, #force?, #trace?, #verbose?
Instance Method Details
#ask(question, answers = nil) ⇒ Object
Convenient method to get simple console reply.
67 68 69 70 71 72 |
# File 'lib/reap/utilities/shellutils.rb', line 67 def ask(question, answers=nil) print "#{question}" print " [#{answers}] " if answers until inp = $stdin.gets ; sleep 1 ; end inp.strip end |
#password(prompt = nil) ⇒ Object
Ask for a password. (FIXME: only for unix so far)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/reap/utilities/shellutils.rb', line 76 def password(prompt=nil) msg ||= "Enter Password: " inp = '' print "#{prompt} " begin #system "stty -echo" #inp = gets.chomp until inp = $stdin.gets sleep 1 end ensure #system "stty echo" end return inp.chomp end |
#sh(cmd) ⇒ Object
Shell runner.
55 56 57 58 59 60 61 62 63 |
# File 'lib/reap/utilities/shellutils.rb', line 55 def sh(cmd) if dryrun? puts cmd true else puts "--> system call: #{cmd}" if trace? system(cmd) end end |
#status(message) ⇒ Object
Internal status report. Only output if dryrun or trace mode.
49 50 51 |
# File 'lib/reap/utilities/shellutils.rb', line 49 def status() puts if dryrun? or trace? end |