Parse configuration file from current directory for additional flags #197
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is tackling #160
I added a separate record
Flags
to hold the flags that can be parsed from a configuration file, tentativelydotenv.config
in the current directory.At first, I tried to reuse the
Options
record, but this became messy when dealing with theprogram
argument. I could not find a non-hacky way to deal with that and thought that it would be best to have a separate parser for the flags.Having said that, I extracted the option parsers to separate definitions to reuse as much code as possible and also so that the parsers for flags and options keep in sync.
applyFlags
takes care of combining the flags from command line arguments and the configuration file.<>
for list arguments is a natural combination, and I believe||
for booleans also works correctly.Some execution examples:
Command:
Output:
Another example:
Command:
Output:
I print a special message when errors come from the config file so the user knows where to look.
I might be missing something, what do you think?
Also, I had to add
directory
as a dependency to check for the file existence, but if there is a better way to do this without adding an extra dependency that would be great.