Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for raw strings and no interpolation #95

Merged
merged 15 commits into from
Mar 11, 2024

Conversation

techouse
Copy link
Collaborator

@techouse techouse commented Mar 7, 2024

Adds support for raw strings (i.e r'some string$', r'foo$bar#baz%qux', etc.) to be passed from env files to generated dart files using either:

  • the @Envied(rawStrings: true) annotation option which will generate all Strings as raw
  • the @EnviedField(rawString: true) annotation option which will generate only the annotated String field as raw

Example:

@Envied(path: 'test/.env.example')
abstract class Env {
  @EnviedField()
  static const String? testString;
  @EnviedField(rawString: true)
  static const String? testUnescapedString;
}

@Envied(path: 'test/.env.example', rawStrings: true)
abstract class Env2 {
  @EnviedField()
  static const String? testString;
  @EnviedField()
  static const String? testUnescapedString;
}

Additionally, I have added the option to disable $BASH_VAR interpolation using either:

  • @Envied(interpolate: false)
  • @EnviedField(interpolate: false)

It should be used in conjunction with rawString if the user plans on using any chars that might cause throw exceptions, i.e. $.

@EnviedField(
  rawString: true,
  interpolate: false
)
static const String? testUnescapedString; // r'foo$bar%baz|qux#'

Fixes #94

@techouse techouse requested a review from petercinibulk as a code owner March 7, 2024 22:47
@techouse techouse mentioned this pull request Mar 7, 2024
@techouse techouse added the enhancement New feature or request label Mar 9, 2024
@techouse techouse marked this pull request as draft March 9, 2024 10:46
@techouse techouse marked this pull request as ready for review March 9, 2024 14:03
@techouse techouse marked this pull request as draft March 9, 2024 14:07
@techouse techouse marked this pull request as ready for review March 9, 2024 14:26
@techouse
Copy link
Collaborator Author

techouse commented Mar 9, 2024

@petercinibulk this will require some scrutiny, so please hammer at it once you have time 😎

@techouse techouse changed the title feat: add support for raw strings feat: add support for raw strings and no interpolation Mar 9, 2024
Copy link
Owner

@petercinibulk petercinibulk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to go! Great work as always and thank you! 🙌🏻

@techouse techouse merged commit ca04a3e into main Mar 11, 2024
10 checks passed
@techouse techouse deleted the fix/issue-94-raw-strings branch March 11, 2024 17:12
techouse added a commit that referenced this pull request Mar 11, 2024
### Changes

---

Packages with breaking changes:

 - There are no breaking changes in this release.

### Packages with other changes:

 - [`envied` - `v0.5.4`](#envied---v054)
 - [`envied_generator` - `v0.5.4`](#enviedgenerator---v054)

---

#### `envied` - `v0.5.4`

 - **FEAT**: add support for raw strings and no interpolation (#95)
 - **FEAT**: add @envied annotation with default options (#92)

#### `envied_generator` - `v0.5.4`

 - **FEAT**: add support for raw strings and no interpolation (#95)
@techouse techouse mentioned this pull request Mar 11, 2024
petercinibulk pushed a commit that referenced this pull request Apr 2, 2024
### Changes

---

Packages with breaking changes:

 - There are no breaking changes in this release.

### Packages with other changes:

 - [`envied` - `v0.5.4`](#envied---v054)
 - [`envied_generator` - `v0.5.4`](#enviedgenerator---v054)

---

#### `envied` - `v0.5.4`

 - **FEAT**: add support for raw strings and no interpolation (#95)
 - **FEAT**: add @envied annotation with default options (#92)

#### `envied_generator` - `v0.5.4`

 - **FEAT**: add support for raw strings and no interpolation (#95)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when value has $
2 participants