Class: Quarantine::CLI
- Inherits:
-
Object
- Object
- Quarantine::CLI
- Extended by:
- T::Sig
- Defined in:
- lib/quarantine/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #create_tables ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
15 16 17 18 19 20 21 22 |
# File 'lib/quarantine/cli.rb', line 15 def initialize # default options @options = T.let( { test_statuses_table_name: 'test_statuses' }, T::Hash[Symbol, T.untyped] ) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/quarantine/cli.rb', line 12 def @options end |
Instance Method Details
#create_tables ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/quarantine/cli.rb', line 57 def create_tables dynamodb = Quarantine::Databases::DynamoDB.new(region: @options[:region]) attributes = [ { attribute_name: 'id', attribute_type: 'S', key_type: 'HASH' } ] additional_arguments = { provisioned_throughput: { read_capacity_units: 10, write_capacity_units: 5 } } begin dynamodb.create_table(@options[:test_statuses_table_name], attributes, additional_arguments) rescue Quarantine::DatabaseError => e warn "#{e.cause&.class}: #{e.cause&.}" end end |
#parse ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/quarantine/cli.rb', line 25 def parse OptionParser.new do |parser| parser. = 'Usage: quarantine_dynamodb [options]' parser.on('-rREGION', '--region=REGION', String, 'Specify the aws region for DynamoDB') do |region| @options[:region] = region end parser.on( '-qTABLE', '--quarantine_table=TABLE', String, "Specify the table name for the quarantine list | Default: #{@options[:test_statuses_table_name]}" ) do |table_name| @options[:test_statuses_table_name] = table_name end parser.on('-h', '--help', 'Prints help page') do puts parser # rubocop:disable Rails/Output exit end end.parse! if @options[:region].nil? error_msg = 'Failed to specify the required aws region with -r option'.freeze warn error_msg raise ArgumentError.new(error_msg) end end |