How did the code itself go?
It took a bit of time to figure out how to parse the config.toml
file. I decided to use the TOML Parser, which converts TOML to an object. With this, I was able to extract the data from the config file we received from the command line.
With the new feature of supporting the -c
and --config
options:
- Users can specify options in a TOML formatted config file without having to pass all of them as command line arguments.
- If there is no config file or if there's an error during parsing, the program will exit with the corresponding error message.
You can find PR from here.
const toml = require('toml');
const concat = require('concat-stream');
const fs = require('fs');
...
program
...
.option('-c, --config <d>', 'specify the file path to a TOML-based config file','')
...
.action((input, options) => {
try {
if(options.config) {
if(path.extname(options.config)!=='.toml') {
throw new Error('Extension of config file should be .toml');
}
fs.createReadStream(options.config, 'utf8').on('error', onError).pipe(concat(function(data) {
try {
const parsedOptions = toml.parse(data);
// when config file is missing any option, use the default value
parsedOptions.output = parsedOptions.output || 'til';
parsedOptions.stylesheet = parsedOptions.stylesheet || null;
parsedOptions.lang = parsedOptions.lang || 'en-CA';
processFile(input, parsedOptions);
} catch(err) {
console.log(err.message);
return process.exit(-1);
}
}));
} else {
processFile(input, options);
}
} catch (err) {
console.log(err.message);
return process.exit(-1);
}
function onError(err) {
console.error(err.message);
console.error('Failed to parse the config file');
return process.exit(-1);
}
What did I learn today?
Steps to review and test other's PR via remotes
1.Add a git remote.
$ git remote add <name-of-student> <https://git-url-of-other-student-fork.git>
Example) git remote add abc123 https://github.com/abc123/til_tracker.git
You will now see the two remotes as below.
$ git remote -v
origin https://github.com/avelynhc/til_tracker.git (fetch)
origin https://github.com/avelynhc/til_tracker.git (push)
abc123 https://github.com/abc123/til_tracker.git (fetch)
abc123 https://github.com/abc123/til_tracker.git (push)
2.Download all the commits and branches of other student in the remote repo to my local repo.
$ git fetch <name-of-student>
Example) git fetch abc123
3.Create a branch pointing to the same commit as the other student's repo and branch. You can use this branch to review and test their work.
$ git checkout -b <branch-name> <name-of-student>/<branch-name>
Example) git checkout -b issue-10 abc123/issue-10
4.If other student pushed another commits and you want to update your local tracking branch, you can do the following.
$ git pull <name-of-student> issue-10
Example) git pull abc123 issue-10
Top comments (0)