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

Use ConfigurationParser library to parse configuration#120

Merged
liamnichols merged 9 commits intomainCreateAPI/CreateAPI:mainfrom
ln/swift-configuration-parserCreateAPI/CreateAPI:ln/swift-configuration-parserCopy head branch name to clipboard
Aug 8, 2022
Merged

Use ConfigurationParser library to parse configuration#120
liamnichols merged 9 commits intomainCreateAPI/CreateAPI:mainfrom
ln/swift-configuration-parserCreateAPI/CreateAPI:ln/swift-configuration-parserCopy head branch name to clipboard

Conversation

@liamnichols
Copy link
Member

@liamnichols liamnichols commented Aug 7, 2022

Background

While it was only recently that I introduces Sourcery templates for generating decoder logic for the ConfigOptions file, it actually lead me to take some inspiration from Swift Argument Parser and to write my own mini library called ConfigurationParser.

Similar to ArgumentParser, it lets you define ParsableConfiguration types and brings all kinds of useful improvements compared to just decoding data using YAMLDecoder that we had been taking advantage of.

The result is that a lot of the custom decoding code written in the CreateOptions target is now no longer required. In this change I delete it all and I update ConfigOptions to become a ParsableConfiguration type which involves the following:

  1. Conform to the ParsableConfiguration protocol (no requirements other than init()
  2. Annotate every property as an @Option
    • This allows the parser to discover the property and its default value.
    • It also allows us to read all option metadata via ConfigOptions.options which is powerful (read on).

Since I deleted the custom decoding code, I did also have to make up for it since that's how #111 worked. To combat this, I introduced a small @OptionSetDecodable property wrapper that handles things.

While in this change we are just using the library to replicate what we previously did manually, there are two other powerful features that I hope to take advantage of:

Overrides

ConfigurationParser allows you to pass overrides when parsing, we can pull these from the CLI arguments which helps with #47 because in theory you can override anything via the command line arguments.

Documentation

The @Option annotation lets you include documentation and we can leverage this with a plugin that can replace Sourcery in terms of generating documentation.

@liamnichols liamnichols self-assigned this Aug 7, 2022
@liamnichols liamnichols force-pushed the ln/swift-configuration-parser branch 2 times, most recently from 8af1098 to e48f167 Compare August 7, 2022 16:51
@liamnichols liamnichols force-pushed the ln/swift-configuration-parser branch from e48f167 to f908b40 Compare August 8, 2022 08:38
@liamnichols liamnichols merged commit 66d4307 into main Aug 8, 2022
@liamnichols liamnichols deleted the ln/swift-configuration-parser branch August 8, 2022 08:48
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

Comments

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