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
- .run(command) ⇒ Object
- .sanitize_command(command) ⇒ Object
- .success?(command) ⇒ Boolean
Class Method Details
.ask(question) ⇒ Object
11 12 13 14 |
# File 'lib/mac_setup/shell.rb', line 11 def ask(question) puts question gets.strip end |
.command_present?(command) ⇒ Boolean
25 26 27 |
# File 'lib/mac_setup/shell.rb', line 25 def command_present?(command) success?("command -v #{command} >/dev/null 2>&1") end |
.password ⇒ Object
16 17 18 19 |
# File 'lib/mac_setup/shell.rb', line 16 def password puts "Enter Password" STDIN.noecho(&:gets).strip 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
29 30 31 32 33 34 35 |
# File 'lib/mac_setup/shell.rb', line 29 def sanitize_command(command) if command.respond_to?(:each) Shellwords.join(command) else command end end |
.success?(command) ⇒ Boolean
21 22 23 |
# File 'lib/mac_setup/shell.rb', line 21 def success?(command) system(sanitize_command(command)) end |