Class: Cp8Cli::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/cp8_cli/command.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



11
12
13
# File 'lib/cp8_cli/command.rb', line 11

def client
  @client
end

Instance Method Details

#ask(message, required: true, default: nil) ⇒ Object



33
34
35
# File 'lib/cp8_cli/command.rb', line 33

def ask(message, required: true, default: nil)
  tty.ask(message, required: required, default: default)
end

#error(message) ⇒ Object



37
38
39
40
# File 'lib/cp8_cli/command.rb', line 37

def error(message)
  say(message.red.bold)
  exit(false)
end

#open_url(url) ⇒ Object



16
17
18
19
# File 'lib/cp8_cli/command.rb', line 16

def open_url(url)
  return title(url) if ENV['BROWSER'] == 'echo'
  `#{OS.open_file_command} \"#{url}\"`
end

#read(command) ⇒ Object



48
49
50
# File 'lib/cp8_cli/command.rb', line 48

def read(command)
  `#{command}`.strip.presence
end

#run(command, title: nil) ⇒ Object



42
43
44
45
46
# File 'lib/cp8_cli/command.rb', line 42

def run(command, title: nil)
  title(title) if title
  say(command)
  system(command) || error("Error running: #{command}")
end

#say(*args) ⇒ Object



25
26
27
# File 'lib/cp8_cli/command.rb', line 25

def say(*args)
  highline.say(*args)
end

#success(message) ⇒ Object



29
30
31
# File 'lib/cp8_cli/command.rb', line 29

def success(message)
  highline.say(message.green.bold)
end

#title(message) ⇒ Object



21
22
23
# File 'lib/cp8_cli/command.rb', line 21

def title(message)
  highline.say(message.bold)
end