Class: Bcli::Command
- Inherits:
-
Object
show all
- Defined in:
- lib/bcli/command.rb
Instance Method Summary
collapse
Instance Method Details
#ask(question) ⇒ Object
95
96
97
98
99
|
# File 'lib/bcli/command.rb', line 95
def ask(question)
prompt.ask(question) do |q|
q.required true
end
end
|
#client ⇒ Object
80
81
82
|
# File 'lib/bcli/command.rb', line 80
def client
@client ||= Bcli::Client.new
end
|
#config ⇒ Object
69
70
71
72
|
# File 'lib/bcli/command.rb', line 69
def config
@config ||= Bcli::Config.new
end
|
#credentials ⇒ Object
75
76
77
|
# File 'lib/bcli/command.rb', line 75
def credentials
config.creds
end
|
#download(url) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/bcli/command.rb', line 50
def download(url)
require "open-uri"
filename = File.basename(url)
remote_file = URI.open(url)
File.write(filename, remote_file.read)
remote_file.close
file_path = File.expand_path(filename)
puts pastel.green "Downloaded #{filename} to #{file_path}"
end
|
#execute ⇒ Object
8
9
10
11
12
13
|
# File 'lib/bcli/command.rb', line 8
def execute(*)
raise(
NotImplementedError,
"#{self.class}##{__method__} must be implemented"
)
end
|
#link_to(url, title = nil) ⇒ Object
38
39
40
41
42
|
# File 'lib/bcli/command.rb', line 38
def link_to(url, title = nil)
require "tty-link"
TTY::Link.link_to(url, title)
end
|
#logger ⇒ Object
44
45
46
47
|
# File 'lib/bcli/command.rb', line 44
def logger
require "tty-logger"
TTY::Logger.new
end
|
#open_in_browser(url) ⇒ Object
85
86
87
|
# File 'lib/bcli/command.rb', line 85
def open_in_browser(url)
system("open", url)
end
|
#parse_json(response) ⇒ Object
90
91
92
|
# File 'lib/bcli/command.rb', line 90
def parse_json(response)
JSON.parse(response.body, object_class: OpenStruct)
end
|
#pastel ⇒ Object
63
64
65
66
|
# File 'lib/bcli/command.rb', line 63
def pastel
require "pastel"
@pastel ||= Pastel.new
end
|
#prompt ⇒ Object
32
33
34
35
|
# File 'lib/bcli/command.rb', line 32
def prompt
require "tty-prompt"
TTY::Prompt.new
end
|