Class: Suma::Cli::GenerateSchemas

Inherits:
Thor
  • Object
show all
Defined in:
lib/suma/cli/generate_schemas.rb

Overview

GenerateSchemas command to generate Schemas YAML by Metanorma YAML

Constant Summary collapse

YAML_FILE_EXTENSIONS =
[".yaml", ".yml"].freeze

Instance Method Summary collapse

Instance Method Details

#generate_schemas(metanorma_manifest_file, schema_manifest_file) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/suma/cli/generate_schemas.rb', line 19

def generate_schemas(metanorma_manifest_file, schema_manifest_file) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  metanorma_manifest_file = File.expand_path(metanorma_manifest_file)

  unless File.exist?(metanorma_manifest_file)
    raise Errno::ENOENT, "Specified file `#{metanorma_manifest_file}` " \
                         "not found."
  end

  unless File.file?(metanorma_manifest_file)
    raise ArgumentError, "Specified path `#{metanorma_manifest_file}` " \
                         "is not a file."
  end

  [metanorma_manifest_file, schema_manifest_file].each do |file|
    if !YAML_FILE_EXTENSIONS.include?(File.extname(file))
      raise ArgumentError, "Specified file `#{file}` is not a YAML file."
    end
  end

  run(
    metanorma_manifest_file, schema_manifest_file,
    exclude_paths: options[:exclude_paths]
  )
end