summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core.zig78
1 files changed, 78 insertions, 0 deletions
diff --git a/core.zig b/core.zig
new file mode 100644
index 0000000..087de9b
--- /dev/null
+++ b/core.zig
@@ -0,0 +1,78 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4const os = std.os;
5const is_windows = builtin.os == Os.windows;
6
7pub fn Param(comptime Id: type) type {
8 return struct {
9 const Self = this;
10
11 id: Id,
12 short: ?u8,
13 long: ?[]const u8,
14 index: ?usize,
15 takes_value: bool,
16 required: bool,
17
18 /// Initialize a parameter.
19 /// If ::name.len == 0, then it's a value parameter: "some-command value".
20 /// If ::name.len == 1, then it's a short parameter: "some-command -s".
21 /// If ::name.len > 1, then it's a long parameter: "some-command --long".
22 pub fn init(id: Id, name: []const u8) Self {
23 return {
24 .id = id,
25 .short = if (name.len == 1) name[0] else null,
26 .long = if (name.len > 1) name else null,
27 .index = null,
28 .takes_value = false,
29 .required = false,
30 };
31 }
32
33 pub fn with(param: &const Self, comptime field_name: []const u8, value: var) Self {
34 var res = *param;
35 @field(res, field_name) = value;
36 return res;
37 }
38 };
39}
40
41pub fn Arg(comptime Id: type) type {
42 return struct {
43 id: Id,
44 value: ?[]const u8,
45 };
46}
47
48
49pub fn args() ArgIterator {
50 return ArgIterator.init();
51}
52
53pub fn Iterator(comptime Id: type) type {
54 return struct {
55 const Self = this;
56 const Buffer = if (is_windows) [1024 * 2]u8 else void;
57
58 windows_buffer: Buffer,
59 params: Param(Id),
60 args: os.ArgIterator,
61 exe: []const u8,
62
63 pub fn init(params: []const Param(Id)) Self {
64 return Self {
65 .params = params,
66 .
67 };
68 }
69
70 fn innerNext(iter: &Self) ?[]const u8 {
71 //if (builtin.os == Os.windows) {
72 // return iter.args.next(allocator);
73 //} else {
74 // return iter.args.nextPosix();
75 //}
76 }
77 }
78}