Skip to content

Commit

Permalink
feat: make a better example
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanaasagi committed Jun 24, 2023
1 parent 8364bcb commit a6bec6d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
5 changes: 1 addition & 4 deletions examples/.env3
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
VAR="
multiline
variable
"
HOME="/home/koyori"
2 changes: 1 addition & 1 deletion examples/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const pkg_path = "../src/lib.zig";
const examples = .{
"basic",
"substitution",
"multiline",
"dry-run",
};

pub fn build(b: *std.build.Builder) void {
Expand Down
32 changes: 32 additions & 0 deletions examples/dry-run/main.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const std = @import("std");
const Loader = @import("dotenv").Loader;

pub fn main() !void {
const allocator = std.heap.page_allocator;

std.debug.print(
"Before => HOME={s}\n",
.{std.os.getenv("HOME") orelse ""},
);

var loader = Loader(.{ .dry_run = true }).init(allocator);
defer loader.deinit();

try loader.loadFromFile(".env3");

std.debug.print(
"After => HOME={s}\n",
.{std.os.getenv("HOME") orelse ""},
);

std.debug.print("Process envs have not been modified!\n\n", .{});
std.debug.print("Now list envs from the file:\n", .{});

var it = loader.envs().iterator();
while (it.next()) |*entry| {
std.debug.print(
"{s}={s}\n",
.{ entry.key_ptr.*, entry.value_ptr.*.? },
);
}
}
12 changes: 0 additions & 12 deletions examples/multiline/main.zig

This file was deleted.

0 comments on commit a6bec6d

Please sign in to comment.