Class: Cp8Cli::Command
- Inherits:
-
Object
- Object
- Cp8Cli::Command
- Defined in:
- lib/cp8_cli/command.rb
Class Attribute Summary collapse
-
.client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #ask(message, required: true, default: nil) ⇒ Object
- #error(message) ⇒ Object
- #open_url(url) ⇒ Object
- #read(command) ⇒ Object
- #run(command) ⇒ Object
- #say(*args) ⇒ Object
- #success(message) ⇒ Object
- #title(message) ⇒ Object
Class Attribute Details
.client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/cp8_cli/command.rb', line 10 def client @client end |
Instance Method Details
#ask(message, required: true, default: nil) ⇒ Object
28 29 30 |
# File 'lib/cp8_cli/command.rb', line 28 def ask(, required: true, default: nil) tty.ask(, required: required, default: default) end |
#error(message) ⇒ Object
36 37 38 39 |
# File 'lib/cp8_cli/command.rb', line 36 def error() say(.red.bold) exit(false) end |
#open_url(url) ⇒ Object
15 16 17 18 |
# File 'lib/cp8_cli/command.rb', line 15 def open_url(url) return title(url) if ENV['BROWSER'] == 'echo' `open \"#{url}\"` end |
#read(command) ⇒ Object
46 47 48 |
# File 'lib/cp8_cli/command.rb', line 46 def read(command) `#{command}`.strip.presence end |
#run(command) ⇒ Object
41 42 43 44 |
# File 'lib/cp8_cli/command.rb', line 41 def run(command) title(command) system(command) || error("Error running: #{command}") end |
#say(*args) ⇒ Object
20 21 22 |
# File 'lib/cp8_cli/command.rb', line 20 def say(*args) highline.say(*args) end |
#success(message) ⇒ Object
24 25 26 |
# File 'lib/cp8_cli/command.rb', line 24 def success() highline.say(.green.bold) end |
#title(message) ⇒ Object
32 33 34 |
# File 'lib/cp8_cli/command.rb', line 32 def title() highline.say(.bold) end |