diff --git a/lib/ea/cli/app.rb b/lib/ea/cli/app.rb index c580350..c783ec8 100644 --- a/lib/ea/cli/app.rb +++ b/lib/ea/cli/app.rb @@ -12,6 +12,11 @@ class App < Thor # search, and every output-bearing command honours the same flag. OUTPUT_OPTION = { type: :string, aliases: :o }.freeze + # Shared kwargs for any command that accepts a YAML config file. + # Matches the OUTPUT_OPTION pattern so adding config-file support + # to another command is a one-line addition. + CONFIG_OPTION = { type: :string, aliases: :c }.freeze + class << self def exit_on_failure? true @@ -72,6 +77,9 @@ def convert(file) desc "spa FILE", "Generate single-page app (SPA) from QEA/XMI/LUR" option :output, **OUTPUT_OPTION, desc: "Output path (default: .html)" + option :config, **CONFIG_OPTION, + desc: "Path to lutaml-uml static-site YAML config " \ + "(sets title, description, logos, etc.)" option :mode, type: :string, default: "single_file", desc: "Output mode: single_file | multi_file" def spa(file) diff --git a/lib/ea/cli/command/spa.rb b/lib/ea/cli/command/spa.rb index d656b7c..7c8ca2a 100644 --- a/lib/ea/cli/command/spa.rb +++ b/lib/ea/cli/command/spa.rb @@ -29,6 +29,7 @@ def call output: output_path, mode: mode, output_strategy: strategy, + config_path: resolve_config_path, }.compact Lutaml::UmlRepository::StaticSite::Generator @@ -48,6 +49,19 @@ def resolve_output_path options[:output] || default_output_path end + def resolve_config_path + path = options[:config] + return nil unless path + + expanded = File.expand_path(path) + unless File.exist?(expanded) + raise Ea::Cli::FileNotFound, + "Config file not found: #{path}" + end + + expanded + end + def default_output_path base = File.basename(file_path, ".*") dir = File.dirname(file_path) diff --git a/spec/ea/cli/app_spec.rb b/spec/ea/cli/app_spec.rb index 47cf012..f47449c 100644 --- a/spec/ea/cli/app_spec.rb +++ b/spec/ea/cli/app_spec.rb @@ -61,4 +61,41 @@ expect(File.size(@convert_out)).to be > 1_000 end end + + describe "config flag" do + let(:qea_fixture) { fixtures_path("basic.qea") } + + after { FileUtils.rm_f([@spa_out, @tmp_config].compact) } + + it "exposes -c as alias for --config on the spa command" do + output = capture_stdout { described_class.start(%w[help spa]) } + expect(output).to match(/-c,\s+\[--config=CONFIG\]/) + end + + it "applies the config title to the generated SPA" do + @spa_out = "/tmp/ea_cli_app_spa_config_spec.html" + @tmp_config = "/tmp/ea_cli_app_spa_config_spec.yml" + File.write(@tmp_config, <<~YAML) + metadata: + title: "Spec Test Title" + description: "Spec test description." + YAML + + capture_stdout do + described_class.start(%W[spa #{qea_fixture} -o #{@spa_out} -c #{@tmp_config}]) + end + + content = File.read(@spa_out) + expect(content).to include("Spec Test Title") + expect(content).to include("Spec test description.") + end + + it "raises FileNotFound when the config path does not exist" do + expect { + capture_stdout do + described_class.start(%W[spa #{qea_fixture} -c /tmp/does-not-exist-#{Time.now.to_i}.yml]) + end + }.to raise_error(Ea::Cli::FileNotFound) + end + end end