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

Adding support for a config file #32

Merged
merged 2 commits into from
Oct 8, 2021
Merged

Adding support for a config file #32

merged 2 commits into from
Oct 8, 2021

Conversation

dhillonks
Copy link
Contributor

@dhillonks dhillonks commented Oct 8, 2021

Description

Fixes #31. Added support for a config file using a --config or -c flag.

Only 3 command line arguments are currently supported by the program, and I've added support for all three (input, output and lang). Also since the program is using the arguments directly through argv to generate HTML, I also just assigned the option values to argv after parsing the config file for consistency and to avoid touching any of the HTML generation.

Example:

node server.js -c test.json

test.json

{
    "input": "./Sherlock-Holmes-Selected-Stories",
    "output": "./web",
    "future-feature": "should be ignored for now"
}

Program output:

File name:  Silver Blaze.txt
File name:  The Adventure of the Six Napoleans.txt
File name:  The Adventure of the Speckled Band.txt
File name:  The Naval Treaty.txt
File name:  The Red Headed League.txt
The HTML files have been saved to ./dist!
Title is : Silver Blaze
Title is : THE ADVENTURE OF THE SPECKLED BAND
Title is : The Naval Treaty
Title is : THE ADVENTURE OF THE SIX NAPOLEONS
Title is : The Red Headed League

(NOTE: There is currently an open bug #12 because of which the files were saved to ./dist instead of ./web. This is unrealted to this PR, the changes in this PR correctly parse the output directory however it's hardcoded to ./dist when the HTML is generated. See #12 and #4 .)

Implemented the following:

  • The -c or --config flags accept a file path to a JSON config file.
  • If the file is missing, or can't be parsed as JSON, program exits with an error message.
  • If the -c or --config option is provided, any other options on the command line are ignored.
  • The program will ignore any options in the config file it doesn't recognize.
  • If the config file is missing any options, defaults are used. For example, output defaults to ./dist.

@dhillonks dhillonks marked this pull request as ready for review October 8, 2021 00:34
@DerekJxy
Copy link
Owner

DerekJxy commented Oct 8, 2021

Excellent! Thank you for your contribution!

@DerekJxy DerekJxy merged commit 68c5881 into DerekJxy:master Oct 8, 2021
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.

Support --config with config file
2 participants