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

.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(message, required: true, default: nil)
  tty.ask(message, required: required, default: default)
end

#error(message) ⇒ Object



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

def error(message)
  say(message.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(message)
  highline.say(message.green.bold)
end

#title(message) ⇒ Object



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

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