Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

Sign up

DotEnv handling for Swift

License

NotificationsYou must be signed in to change notification settings

juri/dotenvy

Repository files navigation

Swift build status

DotEnvy is a dotenv file parser for Swift. It allows you to load values from an.env file, similar to the librariesfornode.js,Python,Ruby,Rust1 etc.

DotEnvy supports multiline strings and variable substitution.

Documentation

For more detailed syntax examples and API documentation visit DotEnvy'sdocumentation on Swift Package Index.

Supported format

The dotenv format does not have a specification, but this library supports the common features. The syntaxresembles Bash. Examples:

KEY=valueKEY2 ="quoted value"  KEY3= unquoted value"with" quotes inside# commentKEY4 ='quoted value referring to ${KEY3}'# trailing commentKEY5=unquoted value referring to${KEY4}KEY6="multilinestring"

Error reporting

DotEnvy has helpful error reporting on syntax errors.

letsource=#"""KEY="VALUE"""#do{    _=tryDotEnvironment.parse(string: source)}catchlet error asParseErrorWithLocation{letformatted= error.formatError(source: source)print(formatted)}

outputs

   1: KEY="VALUE                ^Error on line 1: Unterminated quote

Command Line

There's also a command line tool,dotenv-tool. It supports checking dotenv files for syntax errors and convertingthem to JSON. To install, run:

swift build -c releasecp .build/release/dotenv-tool /usr/local/bin

Footnotes

  1. I accidentally used the same name they use; apologies!


[8]ページ先頭

©2009-2025 Movatter.jp