Class: Lutaml::Cli::LmlCommands
- Inherits:
-
Thor
- Object
- Thor
- Lutaml::Cli::LmlCommands
- Includes:
- Lml::HasAttributes
- Defined in:
- lib/lutaml/lml/cli.rb
Overview
Thor CLI commands for LutaML DSL generation and validation.
Constant Summary collapse
- SUPPORTED_FORMATS =
%w[yaml lutaml exp].freeze
- DEFAULT_INPUT_FORMAT =
'lutaml'- DEFAULT_OUTPUT_FORMAT =
'svg'- EXTENSION_FORMAT_MAP =
{ '.svg' => 'svg', '.svgz' => 'svgz', '.png' => 'png', '.gif' => 'gif', '.jpg' => 'jpg', '.jpeg' => 'jpeg', '.pdf' => 'pdf', '.ps' => 'ps', '.eps' => 'eps', '.dot' => 'dot', '.xdot' => 'xdot', '.fig' => 'fig', '.json' => 'json', '.imap' => 'imap', '.cmapx' => 'cmapx' }.freeze
- PARSE_HANDLERS =
{ 'lutaml' => ->(path) { Lutaml::Lml::Parser.parse(File.new(path)) }, 'yaml' => ->(path) { Lutaml::Lml::YamlParser.parse(path.to_s) }, 'yml' => ->(path) { Lutaml::Lml::YamlParser.parse(path.to_s) }, 'exp' => lambda { |path| require 'lutaml/express' Lutaml::Express::Parsers::Exp.parse(File.new(path)) } }.freeze
- FORMATTER_ATTR_TARGETS =
%i[graph edge node].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #compile(path) ⇒ Object
- #generate(*paths) ⇒ Object
-
#initialize(*args) ⇒ LmlCommands
constructor
A new instance of LmlCommands.
- #validate(*paths) ⇒ Object
Methods included from Lml::HasAttributes
Constructor Details
Class Method Details
.exit_on_failure? ⇒ Boolean
257 258 259 |
# File 'lib/lutaml/lml/cli.rb', line 257 def self.exit_on_failure? true end |
Instance Method Details
#compile(path) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/lutaml/lml/cli.rb', line 119 def compile(path) raise Thor::Error, "File does not exist: #{path}" unless File.exist?(path) ns = [:namespace] ? resolve_namespace([:namespace]) : nil result = Lutaml::Lml::ModelCompiler.new(namespace: ns).compile(File.new(path)) result.each_key do |name| say " compiled: #{name}", :green end say "\n#{result.size} class(es) compiled", :green end |
#generate(*paths) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/lutaml/lml/cli.rb', line 74 def generate(*paths) assert_input_paths(paths) @paths = paths.map { |path| Pathname.new(path) } assert_output_path @paths.each { |input_path| process_single_file(input_path) } end |
#validate(*paths) ⇒ Object
97 98 99 100 101 |
# File 'lib/lutaml/lml/cli.rb', line 97 def validate(*paths) assert_input_paths(paths) errors = paths.map { |p| validate_single_file(p) }.compact report_validation(errors) end |