forked from lobo/lambda-zig
add ability for consumers to specify env file / log info & continue if not exists
This commit is contained in:
parent
140f9e9c55
commit
56ac230e5e
2 changed files with 10 additions and 2 deletions
|
|
@ -16,6 +16,10 @@ pub const Config = struct {
|
||||||
|
|
||||||
/// Default IAM role name if not specified via -Drole-name.
|
/// Default IAM role name if not specified via -Drole-name.
|
||||||
default_role_name: []const u8 = "lambda_basic_execution",
|
default_role_name: []const u8 = "lambda_basic_execution",
|
||||||
|
|
||||||
|
/// Default environment file if not specified via -Denv-file.
|
||||||
|
/// If the file doesn't exist, it's silently skipped.
|
||||||
|
default_env_file: ?[]const u8 = ".env",
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Information about the configured Lambda build steps.
|
/// Information about the configured Lambda build steps.
|
||||||
|
|
@ -84,7 +88,7 @@ pub fn configureBuild(
|
||||||
[]const u8,
|
[]const u8,
|
||||||
"env-file",
|
"env-file",
|
||||||
"Path to environment variables file (KEY=VALUE format)",
|
"Path to environment variables file (KEY=VALUE format)",
|
||||||
) orelse null;
|
) orelse config.default_env_file;
|
||||||
const allow_principal = b.option(
|
const allow_principal = b.option(
|
||||||
[]const u8,
|
[]const u8,
|
||||||
"allow-principal",
|
"allow-principal",
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,12 @@ fn loadEnvFile(
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
) !void {
|
) !void {
|
||||||
const file = std.fs.cwd().openFile(path, .{}) catch |err| {
|
const file = std.fs.cwd().openFile(path, .{}) catch |err| {
|
||||||
|
if (err == error.FileNotFound) {
|
||||||
|
std.log.info("Env file '{s}' not found, skipping", .{path});
|
||||||
|
return;
|
||||||
|
}
|
||||||
std.log.err("Failed to open env file '{s}': {}", .{ path, err });
|
std.log.err("Failed to open env file '{s}': {}", .{ path, err });
|
||||||
return error.EnvFileNotFound;
|
return error.EnvFileOpenError;
|
||||||
};
|
};
|
||||||
defer file.close();
|
defer file.close();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue