Raise error if --config file location does not exist or is not valid#125
Merged
liamnichols merged 5 commits intomainCreateAPI/CreateAPI:mainfrom Aug 8, 2022
ln/better-config-validationCreateAPI/CreateAPI:ln/better-config-validationCopy head branch name to clipboard
Merged
Raise error if --config file location does not exist or is not valid#125liamnichols merged 5 commits intomainCreateAPI/CreateAPI:mainfrom ln/better-config-validationCreateAPI/CreateAPI:ln/better-config-validationCopy head branch name to clipboard
--config file location does not exist or is not valid#125liamnichols merged 5 commits intomainCreateAPI/CreateAPI:mainfrom
ln/better-config-validationCreateAPI/CreateAPI:ln/better-config-validationCopy head branch name to clipboard
Conversation
4306614 to
90ee4ff
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Prior to this change, if you ran the following:
The generator would ignore the fact that wrong/path/to/config.yml was an invalid path as long as it had the right extension. Instead, it would just revert to using the default config, which might leave the user confused as to why their options aren't being applied.
It most likely did this because the default value was always set to .create-api.yaml and we don't necessarily expect this file to always exist, and we wouldn't want to error if it didn't since the user didn't explicitly define it.
It was a bit hard to check this in the
Generatecommand with theconfigalone since it's just aStringand Swift Arguments Parser doesn't give you a way to differentiate between default values and user defined values out of the box.For example, if you specified
--config .create-api.yaml(the default value) explicitly, we'd still want to error if that file didn't exist.To fix this, I opted to introduce a new
ConfigFileLocationtype that conforms toExpressibleByArgument. By doing this, I am able to differentiate between the default value, and a user defiled value passed intoinit?(argument:). I then added an extension to expose the resolvedfileURLwhich will throw an error if the file doesn't exist like we expect.I also added some test coverage to make sure errors are thrown (not something we typically do)