Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/ea/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: <basename>.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)
Expand Down
14 changes: 14 additions & 0 deletions lib/ea/cli/command/spa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def call
output: output_path,
mode: mode,
output_strategy: strategy,
config_path: resolve_config_path,
}.compact

Lutaml::UmlRepository::StaticSite::Generator
Expand All @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions spec/ea/cli/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading