Class: MacSetup::Shell
- Inherits:
-
Object
- Object
- MacSetup::Shell
- Defined in:
- lib/mac_setup/shell.rb
Class Method Summary collapse
- .ask(question) ⇒ Object
- .command_present?(command) ⇒ Boolean
- .password ⇒ Object
- .raw(command) ⇒ Object
- .run(command) ⇒ Object
- .sanitize_command(command) ⇒ Object
- .success?(command) ⇒ Boolean
Class Method Details
.ask(question) ⇒ Object
15 16 17 18 |
# File 'lib/mac_setup/shell.rb', line 15 def ask(question) puts question STDIN.gets.strip end |
.command_present?(command) ⇒ Boolean
29 30 31 |
# File 'lib/mac_setup/shell.rb', line 29 def command_present?(command) success?("command -v #{command} >/dev/null 2>&1") end |
.password ⇒ Object
20 21 22 23 |
# File 'lib/mac_setup/shell.rb', line 20 def password puts "Enter Password" STDIN.noecho(&:gets).strip end |
.raw(command) ⇒ Object
11 12 13 |
# File 'lib/mac_setup/shell.rb', line 11 def raw(command) system(command) end |
.run(command) ⇒ Object
7 8 9 |
# File 'lib/mac_setup/shell.rb', line 7 def run(command) `#{sanitize_command(command)}` end |
.sanitize_command(command) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/mac_setup/shell.rb', line 33 def sanitize_command(command) if command.respond_to?(:each) Shellwords.join(command) else command end end |
.success?(command) ⇒ Boolean
25 26 27 |
# File 'lib/mac_setup/shell.rb', line 25 def success?(command) system(sanitize_command(command)) end |