Class: Glossarist::CLI::ExportCommand
- Inherits:
-
Object
- Object
- Glossarist::CLI::ExportCommand
- Defined in:
- lib/glossarist/cli/export_command.rb
Constant Summary collapse
- AGGREGATE_FORMATS =
%w[jsonld turtle tbx jsonl].freeze
- PER_CONCEPT_FORMATS =
%w[json jsonld turtle yaml].freeze
- EXTENSIONS =
{ "json" => "json", "yaml" => "yaml", **GcrPackage::COMPILED_EXTENSIONS, }.freeze
Instance Method Summary collapse
-
#initialize(path, options) ⇒ ExportCommand
constructor
A new instance of ExportCommand.
- #run ⇒ Object
Constructor Details
#initialize(path, options) ⇒ ExportCommand
Returns a new instance of ExportCommand.
15 16 17 18 |
# File 'lib/glossarist/cli/export_command.rb', line 15 def initialize(path, ) @path = path @options = end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/glossarist/cli/export_command.rb', line 20 def run formats = parse_formats(@options[:format]) output_dir = File.(@options[:output]) FileUtils.mkdir_p(output_dir) concepts = load_concepts name = resolve_shortname formats.each do |format| if per_concept? && per_concept_supported?(format) export_per_concept(concepts, format, output_dir) end if aggregate? export_aggregate(format, concepts, name, output_dir) elsif per_concept? && !per_concept_supported?(format) raise ArgumentError, format( "Per-concept export is not supported for '%<format>s' " \ "(only aggregate). Drop --per-concept or pick one of: %<formats>s", format: format, formats: PER_CONCEPT_FORMATS.join(", "), ) end end validate_outputs!(formats, output_dir, name) if validate? rescue ArgumentError => e warn "Error: #{e.}" exit 1 end |