Class: SchwabRb::CLI::App

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

Overview

Minimal command dispatcher for the gem’s built-in CLI. rubocop:disable Metrics/ClassLength

Constant Summary collapse

DEFAULT_HISTORY_DIR =
"~/.schwab_rb/data/history"
DEFAULT_OPTIONS_DIR =
"~/.schwab_rb/data/options"
SUPPORTED_FORMATS =
%w[csv json].freeze
PERIOD_TYPES =
{
  "day" => SchwabRb::PriceHistory::PeriodTypes::DAY,
  "month" => SchwabRb::PriceHistory::PeriodTypes::MONTH,
  "year" => SchwabRb::PriceHistory::PeriodTypes::YEAR,
  "ytd" => SchwabRb::PriceHistory::PeriodTypes::YEAR_TO_DATE
}.freeze
FREQUENCY_ALIASES =
SchwabRb::PriceHistory::Downloader::FREQUENCY_ALIASES

Instance Method Summary collapse

Constructor Details

#initialize(env: ENV, stdout: $stdout, stderr: $stderr) ⇒ App

Returns a new instance of App.



26
27
28
29
30
# File 'lib/schwab_rb/cli/app.rb', line 26

def initialize(env: ENV, stdout: $stdout, stderr: $stderr)
  @env = env
  @stdout = stdout
  @stderr = stderr
end

Instance Method Details

#call(argv) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/schwab_rb/cli/app.rb', line 32

def call(argv)
  command = argv.shift

  case command
  when nil, "help", "--help", "-h"
    handle_help(argv)
  when "login"
    (argv)
  when "price-history"
    handle_price_history(argv)
  when "sample"
    handle_option_sample(argv)
  else
    print_error("Unknown command `#{command}`.\n\n#{root_help}")
    1
  end
rescue OptionParser::ParseError, ArgumentError, Error => e
  print_error(e.message)
  1
end