Skip to content

Commit

Permalink
refactor: rename variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tensorush committed Jul 13, 2024
1 parent d882bd7 commit 24f07f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/liza.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ const LIB_EXAMPLE1 = @embedFile(TEMPLATES_PATH ++ LIB_PATH ++ EXAMPLE1_PATH ++ E
const LIB_EXAMPLE2 = @embedFile(TEMPLATES_PATH ++ LIB_PATH ++ EXAMPLE2_PATH ++ EXE_SRC_PATH);

pub fn initialize(
codebase_title: []const u8,
codebase_name: []const u8,
codebase_desc: []const u8,
user_handle: []const u8,
user_name: []const u8,
is_lib: bool,
) !void {
var codebase_dir = blk: {
const cur_dir = std.fs.cwd();
_ = cur_dir.access(codebase_title, .{}) catch break :blk try cur_dir.makeOpenPath(codebase_title, .{});
_ = cur_dir.access(codebase_name, .{}) catch break :blk try cur_dir.makeOpenPath(codebase_name, .{});
@panic("Codebase directory already exists!");
};
defer codebase_dir.close();
Expand All @@ -79,21 +79,21 @@ pub fn initialize(
try createPlain(EXE_SRC_PATH, LIB_EXAMPLE1, example1_dir);
try createPlain(EXE_SRC_PATH, LIB_EXAMPLE2, example2_dir);
try createCi("example", workflows_dir);
try createBuild(BUILD_ZIG_PATH, LIB_BUILD_ZIG, codebase_title, codebase_dir);
try createBuild(BUILD_ZIG_ZON_PATH, LIB_BUILD_ZIG_ZON, codebase_title, codebase_dir);
try createReadme(LIB_README, codebase_title, codebase_desc, user_handle, codebase_dir);
try createBuild(BUILD_ZIG_PATH, LIB_BUILD_ZIG, codebase_name, codebase_dir);
try createBuild(BUILD_ZIG_ZON_PATH, LIB_BUILD_ZIG_ZON, codebase_name, codebase_dir);
try createReadme(LIB_README, codebase_name, codebase_desc, user_handle, codebase_dir);
} else {
try createPlain(EXE_SRC_PATH, EXE_SRC, src_dir);
try createCi("exe", workflows_dir);
try createBuild(BUILD_ZIG_PATH, EXE_BUILD_ZIG, codebase_title, codebase_dir);
try createBuild(BUILD_ZIG_ZON_PATH, EXE_BUILD_ZIG_ZON, codebase_title, codebase_dir);
try createReadme(EXE_README, codebase_title, codebase_desc, user_handle, codebase_dir);
try createBuild(BUILD_ZIG_PATH, EXE_BUILD_ZIG, codebase_name, codebase_dir);
try createBuild(BUILD_ZIG_ZON_PATH, EXE_BUILD_ZIG_ZON, codebase_name, codebase_dir);
try createReadme(EXE_README, codebase_name, codebase_desc, user_handle, codebase_dir);
}
}

fn createReadme(
comptime README: []const u8,
codebase_title: []const u8,
codebase_name: []const u8,
codebase_desc: []const u8,
user_handle: []const u8,
codebase_dir: std.fs.Dir,
Expand All @@ -105,7 +105,7 @@ fn createReadme(
while (std.mem.indexOfScalar(u8, README[idx..], '?')) |i| : (idx += i + 2) {
try readme_file.writeAll(README[idx .. idx + i]);
switch (README[idx + i + 1]) {
't' => try readme_file.writeAll(codebase_title),
't' => try readme_file.writeAll(codebase_name),
'd' => try readme_file.writeAll(codebase_desc),
'h' => try readme_file.writeAll(user_handle),
else => try readme_file.writeAll(README[idx + i .. idx + i + 2]),
Expand All @@ -117,7 +117,7 @@ fn createReadme(
fn createBuild(
comptime PATH: []const u8,
comptime TEXT: []const u8,
codebase_title: []const u8,
codebase_name: []const u8,
codebase_dir: std.fs.Dir,
) !void {
var build_file = try codebase_dir.createFile(PATH, .{});
Expand All @@ -126,7 +126,7 @@ fn createBuild(
var idx: usize = 0;
while (std.mem.indexOfScalar(u8, TEXT[idx..], '?')) |i| : (idx += i + 1) {
try build_file.writeAll(TEXT[idx .. idx + i]);
try build_file.writeAll(codebase_title);
try build_file.writeAll(codebase_name);
}
try build_file.writeAll(TEXT[idx..]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ pub fn main() !void {
};
defer res.deinit();

var codebase_title: []const u8 = "liza";
var codebase_name: []const u8 = "liza";
var codebase_desc: []const u8 = "Zig codebase initializer.";
var user_handle: []const u8 = "tensorush";
var user_name: []const u8 = "Jora Troosh";
var is_lib = false;

if (res.positionals.len > 0) {
codebase_title = res.positionals[0];
codebase_name = res.positionals[0];
codebase_desc = res.positionals[1];
user_handle = res.positionals[2];
user_name = res.positionals[3];
Expand All @@ -50,5 +50,5 @@ pub fn main() !void {
return clap.help(std.io.getStdErr().writer(), clap.Help, &PARAMS, .{});
}

try liza.initialize(codebase_title, codebase_desc, user_handle, user_name, is_lib);
try liza.initialize(codebase_name, codebase_desc, user_handle, user_name, is_lib);
}

0 comments on commit 24f07f3

Please sign in to comment.