Fix environment variable
I was freeing the path just after getting it, changed that
This commit is contained in:
parent
e45d8579a9
commit
78d7ed2c0a
13
src/cli.zig
13
src/cli.zig
@ -37,21 +37,19 @@ const State = enum {
|
|||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
const allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
defer {
|
defer switch (gpa.deinit()) {
|
||||||
switch (gpa.deinit()) {
|
.ok => {},
|
||||||
.ok => std.log.debug("No memory leak baby !\n", .{}),
|
.leak => std.log.debug("We fucked it up bro...\n", .{}),
|
||||||
.leak => std.log.debug("We fucked it up bro...\n", .{}),
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const path_env_variable = utils.getEnvVariables(allocator, "ZIPPONDB_PATH");
|
const path_env_variable = utils.getEnvVariables(allocator, "ZIPPONDB_PATH");
|
||||||
|
defer if (path_env_variable) |path| allocator.free(path);
|
||||||
var file_engine: FileEngine = undefined;
|
var file_engine: FileEngine = undefined;
|
||||||
defer file_engine.deinit();
|
defer file_engine.deinit();
|
||||||
|
|
||||||
if (path_env_variable) |path| {
|
if (path_env_variable) |path| {
|
||||||
std.debug.print("Environment variable found: {s}\n", .{path});
|
std.debug.print("Environment variable found: {s}\n", .{path});
|
||||||
file_engine = FileEngine.init(allocator, path_env_variable.?);
|
file_engine = FileEngine.init(allocator, path_env_variable.?);
|
||||||
defer allocator.free(path_env_variable.?);
|
|
||||||
} else {
|
} else {
|
||||||
file_engine = FileEngine.init(allocator, "");
|
file_engine = FileEngine.init(allocator, "");
|
||||||
std.debug.print("No ZIPONDB_PATH envirionment variable found, please use the command:\n db use path/to/db \nor\n db new /path/to/dir\n", .{});
|
std.debug.print("No ZIPONDB_PATH envirionment variable found, please use the command:\n db use path/to/db \nor\n db new /path/to/dir\n", .{});
|
||||||
@ -62,7 +60,6 @@ pub fn main() !void {
|
|||||||
|
|
||||||
var state: State = .expect_main_command;
|
var state: State = .expect_main_command;
|
||||||
|
|
||||||
// TODO: Use a State to prevent first_token and second_token
|
|
||||||
while (true) {
|
while (true) {
|
||||||
std.debug.print("> ", .{});
|
std.debug.print("> ", .{});
|
||||||
const line = try std.io.getStdIn().reader().readUntilDelimiterOrEof(line_buf, '\n');
|
const line = try std.io.getStdIn().reader().readUntilDelimiterOrEof(line_buf, '\n');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user