Module: RDBr::CLIOptions
- Defined in:
- lib/rdbr/cli_options.rb
Class Method Summary collapse
- .add_query_options(parser, options) ⇒ Object
- .defaults ⇒ Object
- .parse(arguments) ⇒ Object
- .parser(options) ⇒ Object
Class Method Details
.add_query_options(parser, options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rdbr/cli_options.rb', line 45 def (parser, ) parser.on('--statement-timeout MS', Integer, 'Query timeout in milliseconds (default: 5000)') do |timeout| [:statement_timeout] = timeout end parser.on('--pool-size COUNT', Integer, 'Database connection pool size (default: 5)') do |size| [:pool_size] = size end parser.on('--checkout-timeout MS', Integer, 'Pool checkout timeout in milliseconds') do |timeout| [:checkout_timeout] = timeout end parser.on('--max-value-bytes BYTES', Integer, 'Maximum bytes returned for one value') do |bytes| [:max_value_bytes] = bytes end parser.on('--max-results COUNT', Integer, 'Maximum rows per page (default: 100)') do |limit| [:max_results] = limit end end |
.defaults ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rdbr/cli_options.rb', line 16 def defaults { host: '127.0.0.1', port: 9292, database_url: ENV['DATABASE_URL'], include_system: false, open_browser: true, statement_timeout: ENV.fetch('RDBR_STATEMENT_TIMEOUT', 5000), pool_size: ENV.fetch('RDBR_POOL_SIZE', 5), checkout_timeout: ENV.fetch('RDBR_CHECKOUT_TIMEOUT', 5000), max_value_bytes: ENV.fetch('RDBR_MAX_VALUE_BYTES', 1_048_576), max_results: ENV.fetch('RDBR_MAX_RESULTS', 100) } end |
.parse(arguments) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/rdbr/cli_options.rb', line 7 def parse(arguments) command = arguments.first&.start_with?('-') ? 'serve' : (arguments.shift || 'serve') = defaults parser().parse!(arguments) raise ArgumentError, 'A database URL is required for inspect' if command == 'inspect' && ![:database_url] [ command, ] end |
.parser(options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rdbr/cli_options.rb', line 31 def parser() OptionParser.new do |parser| parser. = 'Usage: rdbr [serve|inspect|version] [options]' parser.on('--database-url URL', 'Relational database URL'){|url| [:database_url] = url } parser.on('--include-system', 'Include system namespaces'){ [:include_system] = true } parser.on('--host HOST', 'Host to bind (default: 127.0.0.1)'){|host| [:host] = host } parser.on('--port PORT', Integer, 'Port to bind (default: 9292)'){|port| [:port] = port } parser.on('--[no-]open', 'Open the browser when the server is ready (default: true)') do |open| [:open_browser] = open end (parser, ) end end |