Class: Quarantine::CLI
- Inherits:
-
Object
- Object
- Quarantine::CLI
- Defined in:
- lib/quarantine/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#create_tables ⇒ Object
TODO: eventually move to a separate file & create_table by db type when my db adapters.
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 13 14 15 |
# File 'lib/quarantine/cli.rb', line 9 def initialize # default options @options = { quarantine_list_table_name: 'quarantine_list', failed_test_table_name: 'master_failed_tests' } end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/quarantine/cli.rb', line 7 def @options end |
Instance Method Details
#create_tables ⇒ Object
TODO: eventually move to a separate file & create_table by db type when my db adapters
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/quarantine/cli.rb', line 57 def create_tables dynamodb = Quarantine::Databases::DynamoDB.new() attributes = [ { attribute_name: 'id', attribute_type: 'S', key_type: 'HASH' }, { attribute_name: 'build_number', attribute_type: 'S', key_type: 'RANGE' } ] additional_arguments = { provisioned_throughput: { read_capacity_units: 10, write_capacity_units: 5 } } begin dynamodb.create_table([:quarantine_list_table_name], attributes, additional_arguments) rescue Quarantine::DatabaseError => e warn "#{e&.cause&.class}: #{e&.cause&.}" end begin dynamodb.create_table([:failed_test_table_name], attributes, additional_arguments) rescue Quarantine::DatabaseError => e warn "#{e&.cause&.class}: #{e&.cause&.}" end end |
#parse ⇒ Object
17 18 19 20 21 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 49 50 51 52 53 54 |
# File 'lib/quarantine/cli.rb', line 17 def parse OptionParser.new do |parser| parser. = 'Usage: quarantine_dynamodb [options]' parser.on('-rREGION', '--aws_region=REGION', String, 'Specify the aws region for DynamoDB') do |aws_region| [:aws_region] = aws_region end parser.on( '-qTABLE', '--quarantine_table=TABLE', String, "Specify the table name for the quarantine list | Default: #{[:quarantine_list_table_name]}" ) do |table_name| [:quarantine_list_table_name] = table_name end parser.on( '-fTABLE', '--failed_table=TABLE', String, "Specify the table name for the failed test list | Default: #{[:failed_test_table_name]}" ) do |table_name| [:failed_test_table_name] = table_name end parser.on('-h', '--help', 'Prints help page') do puts parser # rubocop:disable Rails/Output exit end end.parse! if [:aws_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 |