-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathzmkdir
More file actions
executable file
·61 lines (51 loc) · 1.41 KB
/
Copy pathzmkdir
File metadata and controls
executable file
·61 lines (51 loc) · 1.41 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env -S java --source 25
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.YearMonth;
enum Format {
FLAT("."),
NESTED("/");
String separator;
Format(String separator) {
this.separator = separator;
}
String format(YearMonth yearMonth) {
return "%d%s%02d".formatted(yearMonth.getYear(), this.separator, yearMonth.getMonthValue());
}
}
void main(String... args) {
var format = parseFormat(args);
var yearMonth = YearMonth.now();
var dirName = format.format(yearMonth);
var path = Path.of(dirName);
try {
Files.createDirectories(path);
System.out.println(path.toAbsolutePath());
} catch (Exception e) {
System.err.println("Failed to create directory: " + e.getMessage());
System.exit(1);
}
}
Format parseFormat(String[] args) {
if (args.length == 0) {
printUsage();
System.exit(1);
}
return switch (args[0]) {
case "-f", "--flat" -> Format.FLAT;
case "-n", "--nested" -> Format.NESTED;
default -> {
printUsage();
System.exit(1);
yield Format.FLAT;
}
};
}
void printUsage() {
System.err.println("""
Usage: zmkdir <format>
Formats:
-f, --flat Create YYYY.MM directory (e.g., 2026.01)
-n, --nested Create YYYY/MM directory (e.g., 2026/01)
""");
}