Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

Raise error if --config file location does not exist or is not valid#125

Merged
liamnichols merged 5 commits intomainCreateAPI/CreateAPI:mainfrom
ln/better-config-validationCreateAPI/CreateAPI:ln/better-config-validationCopy head branch name to clipboard
Aug 8, 2022
Merged

Raise error if --config file location does not exist or is not valid#125
liamnichols merged 5 commits intomainCreateAPI/CreateAPI:mainfrom
ln/better-config-validationCreateAPI/CreateAPI:ln/better-config-validationCopy head branch name to clipboard

Conversation

@liamnichols
Copy link
Member

Prior to this change, if you ran the following:

$ create-api generate --config wrong/path/to/config.yml schema.json

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 Generate command with the config alone since it's just a String and 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 ConfigFileLocation type that conforms to ExpressibleByArgument. By doing this, I am able to differentiate between the default value, and a user defiled value passed into init?(argument:). I then added an extension to expose the resolved fileURL which 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)

@liamnichols liamnichols self-assigned this Aug 8, 2022
@liamnichols liamnichols force-pushed the ln/better-config-validation branch from 4306614 to 90ee4ff Compare August 8, 2022 10:15
@liamnichols liamnichols added this to the 0.1.0 milestone Aug 8, 2022
@liamnichols liamnichols merged commit 5e73d53 into main Aug 8, 2022
@liamnichols liamnichols deleted the ln/better-config-validation branch August 8, 2022 10:42
@liamnichols liamnichols mentioned this pull request Aug 8, 2022
27 tasks
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.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.