├── .env ├── .env-substitution ├── .github ├── codecov.yml └── workflows │ ├── ci.yml │ └── codecov-comment.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Cargo.toml ├── LICENSE ├── README.md ├── ci-check.sh ├── dotenv_codegen ├── Cargo.toml ├── LICENSE ├── README.md ├── src │ └── lib.rs └── tests │ └── basic_dotenv_macro.rs ├── dotenvy-macros ├── Cargo.toml └── src │ └── lib.rs ├── dotenvy ├── Cargo.toml ├── LICENSE ├── README.md └── src │ ├── bin │ └── dotenvy.rs │ ├── err.rs │ ├── iter.rs │ ├── lib.rs │ └── parse.rs └── examples ├── dev-prod ├── Cargo.toml └── src │ └── main.rs ├── env-example ├── env-example-2 ├── find ├── Cargo.toml └── src │ └── main.rs ├── modify-macro ├── Cargo.toml └── src │ └── main.rs ├── modify-tokio-macro ├── Cargo.toml └── src │ └── main.rs ├── modify-tokio ├── Cargo.toml └── src │ └── main.rs ├── modify ├── Cargo.toml ├── print_host.py └── src │ └── main.rs ├── multiple-files ├── Cargo.toml └── src │ └── main.rs ├── non-utf8 ├── Cargo.toml ├── env-example-utf16 └── src │ └── main.rs └── optional ├── Cargo.toml └── src └── main.rs /.env: -------------------------------------------------------------------------------- 1 | # Start of .env file 2 | # Comment line with single ' quote 3 | # Comment line with double " quote 4 | # Comment line, starts with space with double " quote 5 | 6 | CODEGEN_TEST_VAR1="hello!" 7 | CODEGEN_TEST_VAR2="'quotes within quotes'" 8 | CODEGEN_TEST_VAR3="double quoted with # hash in value" 9 | CODEGEN_TEST_VAR4='single quoted with # hash in value' 10 | CODEGEN_TEST_VAR5=not_quoted_with_#_hash_in_value 11 | CODEGEN_TEST_VAR6=not_quoted_with_comment_beheind # var6 comment 12 | CODEGEN_TEST_VAR7=not\ quoted\ with\ escaped\ space 13 | CODEGEN_TEST_VAR8="double quoted with comment beheind" # var7 comment 14 | CODEGEN_TEST_VAR9="Variable starts with a whitespace" 15 | CODEGEN_TEST_VAR10= "Value starts with a whitespace after =" 16 | CODEGEN_TEST_VAR11 ="Variable ends with a whitespace before =" 17 | CODEGEN_TEST_MULTILINE1="First Line 18 | Second Line" 19 | CODEGEN_TEST_MULTILINE2="# First Line Comment 20 | Second Line 21 | #Third Line Comment 22 | Fourth Line 23 | " # multline2 comment 24 | 25 | # End of .env file 26 | -------------------------------------------------------------------------------- /.env-substitution: -------------------------------------------------------------------------------- 1 | VAR=one 2 | VAR_2=two 3 | 4 | # Non-existing values are replaced with an empty string 5 | RESULT=$NOPE #value: '' (empty string) 6 | 7 | # All the letters after $ symbol are treated as the variable name to replace 8 | RESULT=$VAR #value: 'one' 9 | 10 | # Double quotes do not affect the substitution 11 | RESULT="$VAR" #value: 'one' 12 | 13 | # Different syntax, same result 14 | RESULT=${VAR} #value: 'one' 15 | 16 | # Curly braces are useful in cases when we need to use a variable with non-alphanumeric name 17 | RESULT=$VAR_2 #value: 'one_2' since $ with no curly braces stops after first non-alphanumeric symbol 18 | RESULT=${VAR_2} #value: 'two' 19 | 20 | # The replacement can be escaped with either single quotes or a backslash: 21 | RESULT='$VAR' #value: '$VAR' 22 | RESULT=\$VAR #value: '$VAR' 23 | 24 | # Environment variables are used in the substutution and always override the local variables 25 | RESULT=$PATH #value: the contents of the $PATH environment variable 26 | PATH="My local variable value" 27 | RESULT=$PATH #value: the contents of the $PATH environment variable, even though the local variable is defined -------------------------------------------------------------------------------- /.github/codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: off 6 | patch: off -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - ci 8 | pull_request: 9 | branches: 10 | - master 11 | 12 | jobs: 13 | tests: 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | # Minimum Supported Rust Version 18 | rust: [stable, nightly, 1.74.0] 19 | on: 20 | - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu } 21 | - { os: macos-latest, target: x86_64-apple-darwin } 22 | - { os: windows-latest, target: x86_64-pc-windows-msvc } 23 | 24 | runs-on: ${{ matrix.on.os }} 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - uses: dtolnay/rust-toolchain@master 29 | with: 30 | toolchain: ${{ matrix.rust }} 31 | target: ${{ matrix.on.target }} 32 | 33 | - name: Cache 34 | uses: Swatinem/rust-cache@v2 35 | with: 36 | shared-key: ${{ matrix.rust }}_${{ matrix.on.os }} 37 | 38 | - name: Build tests 39 | run: cargo test --no-run 40 | 41 | - name: Run tests 42 | run: cargo test 43 | 44 | rustfmt: 45 | runs-on: ubuntu-latest 46 | steps: 47 | - uses: actions/checkout@v4 48 | 49 | - name: Install stable 50 | uses: dtolnay/rust-toolchain@stable 51 | with: 52 | components: rustfmt 53 | 54 | - name: Run rustfmt 55 | run: cargo fmt --all --check 56 | 57 | docs: 58 | runs-on: ubuntu-latest 59 | steps: 60 | - uses: actions/checkout@v4 61 | 62 | - name: Install nightly 63 | uses: dtolnay/rust-toolchain@nightly 64 | 65 | - name: cargo doc 66 | env: 67 | RUSTDOCFLAGS: --cfg docsrs -D warnings 68 | run: cargo doc --no-deps --all-features --document-private-items 69 | 70 | clippy: 71 | runs-on: ubuntu-latest 72 | steps: 73 | - uses: actions/checkout@v4 74 | 75 | - name: Install stable 76 | uses: dtolnay/rust-toolchain@stable 77 | with: 78 | components: clippy 79 | 80 | - name: Cache 81 | uses: Swatinem/rust-cache@v2 82 | with: 83 | shared-key: stable_ubuntu-latest 84 | 85 | - name: Run clippy 86 | run: cargo clippy --all-features --all-targets --workspace -- -D warnings 87 | 88 | codecov: 89 | runs-on: ubuntu-latest 90 | steps: 91 | - uses: actions/checkout@v4 92 | 93 | - name: Install stable toolchain 94 | uses: actions-rs/toolchain@v1 95 | with: 96 | toolchain: stable 97 | override: true 98 | 99 | - name: Check coverage 100 | uses: actions-rs/tarpaulin@v0.1 101 | with: 102 | version: 0.22.0 103 | args: --ignore-tests --workspace -- --test-threads 1 104 | 105 | - name: Archive code coverage results 106 | uses: actions/upload-artifact@v3 107 | with: 108 | name: code_coverage_result 109 | path: cobertura.xml 110 | 111 | # push steps 112 | - name: Upload to codecov.io 113 | uses: codecov/codecov-action@v3 114 | if: github.event_name == 'push' 115 | with: 116 | files: cobertura.xml 117 | 118 | # pull request steps 119 | - name: Note PR number 120 | if: github.event_name == 'pull_request' 121 | env: 122 | PR_NUMBER: ${{ github.event.number }} 123 | run: | 124 | mkdir -p ./pr 125 | printf $PR_NUMBER > ./pr/pr_number 126 | 127 | - name: Save PR number 128 | if: github.event_name == 'pull_request' 129 | uses: actions/upload-artifact@v3 130 | with: 131 | name: pr_number 132 | path: pr/ 133 | -------------------------------------------------------------------------------- /.github/workflows/codecov-comment.yml: -------------------------------------------------------------------------------- 1 | name: codecov-comment 2 | 3 | on: 4 | workflow_run: 5 | workflows: [ci] 6 | types: [completed] 7 | 8 | jobs: 9 | pr: 10 | runs-on: ubuntu-latest 11 | # Only run if workflow was successfully run on a pull_request event 12 | if: ${{ (github.event.workflow_run.conclusion == 'success') && (github.event.workflow_run.event == 'pull_request') }} 13 | env: 14 | # ID of the pull_request's workflow run 15 | PR_RUN_ID: ${{ github.event.workflow_run.id }} 16 | 17 | steps: 18 | - name: Get results 19 | uses: dawidd6/action-download-artifact@v6 20 | with: 21 | workflow: ci.yml 22 | run_id: ${{ env.PR_RUN_ID }} 23 | name: code_coverage_result 24 | 25 | - name: Create report 26 | uses: irongut/CodeCoverageSummary@v1.3.0 27 | with: 28 | filename: cobertura.xml 29 | badge: true 30 | format: markdown 31 | hide_branch_rate: true 32 | hide_complexity: true 33 | indicators: false 34 | output: both 35 | thresholds: "50 75" 36 | 37 | - name: Trim report 38 | # get rid of unnecessary codcov info 39 | # remove any line not containing a link or a comment 40 | run: | 41 | sed -i '/!\[\|