Class: Bcli::Command

Inherits:
Object
  • 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

#clientObject



80
81
82
# File 'lib/bcli/command.rb', line 80

def client
  @client ||= Bcli::Client.new
end

#configObject



69
70
71
72
# File 'lib/bcli/command.rb', line 69

def config
  # require "tty-config"
  @config ||= Bcli::Config.new
end

#credentialsObject



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)
  # rubocop:disable Security/Open
  remote_file = URI.open(url)
  # rubocop:enable Security/Open
  File.write(filename, remote_file.read)
  remote_file.close
  file_path = File.expand_path(filename)
  puts pastel.green "Downloaded #{filename} to #{file_path}"
end

#executeObject

Execute this command

Raises:

  • (NotImplementedError)


8
9
10
11
12
13
# File 'lib/bcli/command.rb', line 8

def execute(*)
  raise(
    NotImplementedError,
    "#{self.class}##{__method__} must be implemented"
  )
end


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

#loggerObject



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

#pastelObject



63
64
65
66
# File 'lib/bcli/command.rb', line 63

def pastel
  require "pastel"
  @pastel ||= Pastel.new
end

#promptObject

The interactive prompt



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

def prompt
  require "tty-prompt"
  TTY::Prompt.new
end