mirror of
https://git.aramjonghu.nl/AramJonghu/nfi.git
synced 2026-06-06 20:38:24 +02:00
some setup for subcommands: do nothing right now, experimenting with pointers
This commit is contained in:
@@ -3,10 +3,6 @@ const std = @import("std");
|
|||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
const mod = b.addModule("nfi", .{
|
|
||||||
.root_source_file = b.path("src/root.zig"),
|
|
||||||
.target = target,
|
|
||||||
});
|
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "nfi",
|
.name = "nfi",
|
||||||
@@ -14,38 +10,22 @@ pub fn build(b: *std.Build) void {
|
|||||||
.root_source_file = b.path("src/main.zig"),
|
.root_source_file = b.path("src/main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.imports = &.{
|
|
||||||
.{ .name = "nfi", .module = mod },
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
|
|
||||||
const run_step = b.step("run", "Run the app");
|
|
||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
run_step.dependOn(&run_cmd.step);
|
|
||||||
|
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
if (b.args) |args| run_cmd.addArgs(args);
|
||||||
|
|
||||||
if (b.args) |args| {
|
const run_step = b.step("run", "Run nfi");
|
||||||
run_cmd.addArgs(args);
|
run_step.dependOn(&run_cmd.step);
|
||||||
}
|
|
||||||
|
|
||||||
const mod_tests = b.addTest(.{
|
|
||||||
.root_module = mod,
|
|
||||||
});
|
|
||||||
|
|
||||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
|
||||||
|
|
||||||
const exe_tests = b.addTest(.{
|
const exe_tests = b.addTest(.{
|
||||||
.root_module = exe.root_module,
|
.root_module = exe.root_module,
|
||||||
});
|
});
|
||||||
|
const run_tests = b.addRunArtifact(exe_tests);
|
||||||
const run_exe_tests = b.addRunArtifact(exe_tests);
|
|
||||||
|
|
||||||
const test_step = b.step("test", "Run tests");
|
const test_step = b.step("test", "Run tests");
|
||||||
test_step.dependOn(&run_mod_tests.step);
|
test_step.dependOn(&run_tests.step);
|
||||||
test_step.dependOn(&run_exe_tests.step);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const db = @import("db.zig");
|
||||||
|
const notify = @import("notify.zig");
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const Reminder = @import("reminder.zig").Reminder;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const sub = @import("subcommands.zig");
|
||||||
|
|
||||||
|
fn eql(a: []const u8, b: []const u8) bool {
|
||||||
|
return std.mem.eql(u8, a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(init: std.process.Init.Minimal) !void {
|
||||||
|
var arg_iter = try std.process.Args.Iterator.initAllocator(init.args, std.heap.page_allocator);
|
||||||
|
defer arg_iter.deinit();
|
||||||
|
|
||||||
|
_ = arg_iter.next();
|
||||||
|
const subcommand = (arg_iter.next()) orelse return;
|
||||||
|
|
||||||
|
for (sub.subcommands) |cmd| {
|
||||||
|
if (std.mem.eql(u8, subcommand, cmd.name)) {
|
||||||
|
return cmd.handler(&arg_iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
const std = @import("std");
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
pub const Reminder = struct {
|
||||||
|
id: u64,
|
||||||
|
title: []const u8,
|
||||||
|
due_at: i64,
|
||||||
|
done: bool,
|
||||||
|
snoozed: bool,
|
||||||
|
created_at: i64,
|
||||||
|
};
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
//! By convention, root.zig is the root source file when making a package.
|
|
||||||
const std = @import("std");
|
|
||||||
const Io = std.Io;
|
|
||||||
|
|
||||||
/// This is a documentation comment to explain the `printAnotherMessage` function below.
|
|
||||||
///
|
|
||||||
/// Accepting an `Io.Writer` instance is a handy way to write reusable code.
|
|
||||||
pub fn printAnotherMessage(writer: *Io.Writer) Io.Writer.Error!void {
|
|
||||||
try writer.print("Run `zig build test` to run the tests.\n", .{});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add(a: i32, b: i32) i32 {
|
|
||||||
return a + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "basic add functionality" {
|
|
||||||
try std.testing.expect(add(3, 7) == 10);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub const Handler = *const fn (*std.process.Args.Iterator) anyerror!void;
|
||||||
|
|
||||||
|
pub const Subcommand = struct {
|
||||||
|
name: []const u8,
|
||||||
|
handler: Handler,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const subcommands = [_]Subcommand{
|
||||||
|
.{ .name = "add", .handler = handleAdd },
|
||||||
|
.{ .name = "remove", .handler = handleRemove },
|
||||||
|
.{ .name = "done", .handler = handleDone },
|
||||||
|
.{ .name = "list", .handler = handleList },
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn handleAdd(args: *std.process.Args.Iterator) !void {
|
||||||
|
_ = args;
|
||||||
|
std.debug.print("add!", .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handleRemove(args: *std.process.Args.Iterator) !void {
|
||||||
|
_ = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handleDone(args: *std.process.Args.Iterator) !void {
|
||||||
|
_ = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handleList(args: *std.process.Args.Iterator) !void {
|
||||||
|
_ = args;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user