Class: BerkeleyLibrary::TIND::Export::ExportCommand
- Inherits:
-
Object
- Object
- BerkeleyLibrary::TIND::Export::ExportCommand
- Extended by:
- Util::SysExits
- Includes:
- Util::SysExits
- Defined in:
- lib/berkeley_library/tind/export/export_command.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- DEFAULT_FORMAT =
ExportFormat::CSV
- FORMATS =
ExportFormat.to_a.map(&:value).join(', ')
- OPTS =
{ f: ['--format FORMAT', "Format (#{FORMATS}; defaults to output file extension, or else to #{DEFAULT_FORMAT})"], o: ['--output-file FILE', 'Output file or directory'], l: ['--list-collections', 'List collection sizes and names'], u: ['--tind-base-url URL', "TIND base URL (default $#{BerkeleyLibrary::TIND::Config::ENV_TIND_BASE_URL})"], k: ['--api-key KEY', "TIND API key (default $#{BerkeleyLibrary::TIND::Config::ENV_TIND_API_KEY})"], e: ['--env-file [ENV]', 'Read environment variables from <ENV> (default: ./.env)'], v: ['--verbose', 'Verbose error logging'], h: ['--help', 'Show help and exit'] }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Class Method Summary collapse
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(*args, out: $stdout) ⇒ ExportCommand
constructor
A new instance of ExportCommand.
Constructor Details
#initialize(*args, out: $stdout) ⇒ ExportCommand
Returns a new instance of ExportCommand.
20 21 22 23 |
# File 'lib/berkeley_library/tind/export/export_command.rb', line 20 def initialize(*args, out: $stdout) @options = ExportCommand.(args) @out = out end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/berkeley_library/tind/export/export_command.rb', line 17 def @options end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
18 19 20 |
# File 'lib/berkeley_library/tind/export/export_command.rb', line 18 def out @out end |
Class Method Details
.parse_options(argv) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/berkeley_library/tind/export/export_command.rb', line 66 def (argv) {}.tap do |opts| option_parser(opts).parse!(argv) opts[:collection] = argv.pop opts[:format] = ensure_format(opts) validate!(opts) configure!(opts) end rescue StandardError => e print_usage_and_exit!($stderr, EX_USAGE, e.) end |
Instance Method Details
#execute! ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/berkeley_library/tind/export/export_command.rb', line 25 def execute! return list_collections if [:list] export_collection rescue StandardError => e warn(e) warn(e.backtrace.join("\n")) if e.backtrace && [:verbose] exit(EX_SOFTWARE) end |