Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collection option related issue #286

Merged
merged 1 commit into from
Sep 26, 2022
Merged

Conversation

abunashir
Copy link
Member

@abunashir abunashir commented Sep 11, 2022

We have recently added support to provide collection options either as a command line arguments or options in 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

@@ -26,8 +27,14 @@ def collection_file
@collection_file ||= Metanorma::Collection.parse(file)
end

def verify_required_options_are_present
if collection_options[:output_folder].nil?
raise ArgumentError.new("Missing a required option '--output-folder'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shoud provide a default path for "output folder" just like how metanorma compile sources/sample.adoc uses the location of the input file as the output folder:

  • metanorma compile sources/sample.adoc => sources/sample.xml output
  • metanorma collection sources/collection.yaml => sources/collection.xml output

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point to set the source path as a default output folder 👍🏼

Actually, after looking into it I came across a bit tricky issue - looks like we are recreating the output folder before we write the outputs, so if we use the source directory as the output path then it gets removed (along with the source file) in the recreation phase - here is the source code.

So, what do you guys think about using ...source/output as a default output directory if nothing was provided?

// @ronaldtse, @opoudjis

Copy link
Contributor

@ronaldtse ronaldtse Sep 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code is clearly wrong, we should NOT be removing the output directory in any case.

We want to use the source path as the default output folder (i.e. my_source/x.yml => my_source/x.{outputformats}). Unless I'm missing something here...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the exact reasoning whey we need to remove the output directory before writing the output. @andrew2net, @opoudjis - Do you guys have any idea why we are doing that, do we still need to keep that logic there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have done it to ensure that only data from the current run was present in the folder. Arguably that's overly cautious. Maybe. Ok, get rid of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I just created a PR for that - metanorma/metanorma#259, once that's merged and released then we can merge this one. FYI, I will update this PR to use the source folder next :)

@abunashir abunashir force-pushed the fix-collection-output-path branch 2 times, most recently from da08dcc to 65a5ace Compare September 14, 2022 13:04
abunashir added a commit to metanorma/metanorma that referenced this pull request Sep 17, 2022
Currently, the collection is re-creating the output directory, and
it might causes issues like removing all files from the output folder.

Normally this is okay, but it become an issue where the user is using
the source path as output directory and it deletes all source files.

This commit changes that, and only tries to create a folder when the
output folder doesn't already exists.

Related: metanorma/metanorma-cli#286
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
@abunashir
Copy link
Member Author

I just updated the PR to use the source file's folder as default output location for collection. Once that is merged and released - metanorma/metanorma#259, please feel free to merge this one :)

//cc: @ronaldtse, @opoudjis

@abunashir abunashir dismissed ronaldtse’s stale review September 17, 2022 12:48

Can you have another look please?

@opoudjis opoudjis merged commit 690e144 into main Sep 26, 2022
@opoudjis opoudjis deleted the fix-collection-output-path branch September 26, 2022 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

metanorma collection collection.yaml does not work without explicit options
3 participants