Skip to content

Commit

Permalink
Fix collection option related issue
Browse files Browse the repository at this point in the history
We have recently added support to provide collection options either
as an command line arguments or options in the collection file. But
that is only working on the site interface, and the collection cli
still expect the `output-folder` as required option.

This commit changes that, so it's not required anymore and it will
try to read the option from the file, and if none of those source
has this value, then it will use the source as output directory.

Fixes #283
  • Loading branch information
abunashir committed Sep 17, 2022
1 parent 03b7eaa commit 4636428
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/metanorma/cli/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def collection_file
@collection_file ||= Metanorma::Collection.parse(file)
end

def source_folder
@source_folder ||= File.dirname(File.expand_path(file))
end

def collection_options
{
@collection_options ||= {
compile: @compile_options,
coverpage: options.fetch(:coverpage, nil),
output_folder: options.fetch(:output_folder, nil),
output_folder: options.fetch(:output_folder, source_folder),
format: collection_output_formats(options.fetch(:format, "")),
}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def compile(file_name = nil)

desc "collection FILENAME", "Render HTML pages from XML/YAML colection"
option :format, aliases: "-x", type: :string, desc: "Formats to generate"
option :output_folder, aliases: "-w", required: true, desc: "Directory to save compiled files"
option :output_folder, aliases: "-w", desc: "Directory to save compiled files"
option :coverpage, aliases: "-c", desc: "Liquid template"
option :agree_to_terms, type: :boolean, desc: "Agree / Disagree with all third-party licensing terms "\
"presented (WARNING: do know what you are agreeing with!)"
Expand Down
23 changes: 21 additions & 2 deletions spec/metanorma/cli/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
context "with specified options" do
it "compiles and renders the collection files" do
collection = mock_collection_instance
Metanorma::Cli::Collection.render(collection_file, format: "html, pdf")

expect(collection).to have_received(:render).with(format: %I(html pdf))
Metanorma::Cli::Collection.render(
collection_file,
format: "html, pdf",
output_folder: "bilingual-brochure",
)

expect(collection).to have_received(:render).with(
format: %I(html pdf), output_folder: "bilingual-brochure",
)
end
end

Expand All @@ -25,6 +32,18 @@
)
end
end

context "with missing options" do
it "usages the source as reference for options" do
collection = mock_collection_instance

Metanorma::Cli::Collection.render(collection_file)

expect(collection).to have_received(:render).with(
hash_including(output_folder: File.dirname(collection_file.to_s)),
)
end
end
end

def collection_file(collection = "collection1.yml")
Expand Down

0 comments on commit 4636428

Please sign in to comment.