Class: Dratools::Commands::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/dratools/commands/base_command.rb

Overview

サブコマンド共通の土台。オプション解析・accession 収集・例外処理・終了コードを担う。

Constant Summary collapse

SUCCESS_EXIT_STATUS =
0
FAILURE_EXIT_STATUS =
1
DEFAULT_FILE_TYPE =
AccessionResolver::FILE_TYPE_SRA
VALID_FILE_TYPES =
[
  AccessionResolver::FILE_TYPE_SRA,
  AccessionResolver::FILE_TYPE_FASTQ,
  AccessionResolver::FILE_TYPE_ALL
].freeze
DEFAULT_PROTOCOL =
DownloadCandidate::HTTPS_PROTOCOL
VALID_PROTOCOLS =
[DownloadCandidate::HTTPS_PROTOCOL, DownloadCandidate::FTP_PROTOCOL].freeze
MISSING_VALUE =

値が無いことを表す TSV のプレースホルダ。

'NA'

Instance Method Summary collapse

Constructor Details

#initialize(argv, resolver:, downloader:, stdout:, stderr:, stdin:) ⇒ BaseCommand

Returns a new instance of BaseCommand.



29
30
31
32
33
34
35
36
37
38
# File 'lib/dratools/commands/base_command.rb', line 29

def initialize(argv, resolver:, downloader:, stdout:, stderr:, stdin:)
  @argv = argv
  @resolver = resolver
  @downloader = downloader
  @stdout = stdout
  @stderr = stderr
  @stdin = stdin
  @options = default_options
  @failed_count = 0
end

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dratools/commands/base_command.rb', line 40

def run
  parse_options
  return @halt unless @halt.nil?

  begin
    accessions = collect_accessions
  rescue MissingAccessionError
    @stderr.puts build_option_parser
    return FAILURE_EXIT_STATUS
  end

  accessions.each do |accession|
    process(accession)
  rescue Error => error
    report_error(error.message, accession: accession)
    @failed_count += 1
  end
  finalize
  @failed_count.zero? ? SUCCESS_EXIT_STATUS : FAILURE_EXIT_STATUS
rescue OptionParser::ParseError, Error => error
  report_error(error.message)
  FAILURE_EXIT_STATUS
end