Class: TogoWS::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/togows/cli.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://togows.org"
DEFAULT_TIMEOUT =
30

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin, stdout, stderr) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
17
18
19
20
# File 'lib/togows/cli.rb', line 13

def initialize(argv, stdin, stdout, stderr)
  @argv = argv.dup
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @out_color = Color.new(Color.enabled_for?(stdout))
  @err_color = Color.new(Color.enabled_for?(stderr))
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/togows/cli.rb', line 22

def run
  command = @argv.shift
  return help_for(@argv.shift, 0) if ["help", "-h", "--help"].include?(command)
  return help(nil, 0) if command.nil?
  return version if ["version", "--version", "-v"].include?(command)

  case command
  when "entry" then run_entry
  when "search" then run_search
  when "convert" then run_convert
  when "databases", "dbs" then run_databases
  when "ucsc" then run_ucsc
  else
    error("unknown command: #{command}")
    help(nil, 2)
  end
rescue HTTPError => e
  error("#{e.code} #{e.message_text}")
  @stderr.puts e.body unless e.body.empty?
  e.code >= 500 ? 5 : 4
rescue OptionParser::ParseError, Error => e
  error(e.message)
  2
rescue SystemCallError, SocketError, Timeout::Error => e
  error("#{e.class}: #{e.message}")
  6
end