-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtouch.zig
36 lines (28 loc) · 1.04 KB
/
touch.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const std = @import("std");
const yazap = @import("yazap");
const allocator = std.heap.page_allocator;
const App = yazap.App;
const Arg = yazap.Arg;
pub fn main() anyerror!void {
var app = App.init(allocator, "mytouch", null);
defer app.deinit();
var touch = app.rootCommand();
touch.setProperty(.help_on_empty_args);
try touch.addArg(Arg.positional("FILE_NAME", null, null));
touch.setProperty(.positional_arg_required);
try touch.addArg(Arg.booleanOption("no-create", 'c', "Do not create any files"));
try touch.addArg(Arg.booleanOption("version", 'v', "Display app version"));
const matches = try app.parseProcess();
if (matches.containsArg("version")) {
std.debug.print("v0.1.0", .{});
return;
}
if (matches.getSingleValue("FILE_NAME")) |file_name| {
if (matches.containsArg("no-create")) {
std.debug.print("I'am not creating it", .{});
} else {
var file = try std.fs.cwd().createFile(file_name, .{});
defer file.close();
}
}
}