|
| 1 | +package dev.dirs.cli; |
| 2 | + |
| 3 | +import dev.dirs.ProjectDirectories; |
| 4 | +import picocli.CommandLine; |
| 5 | +import picocli.CommandLine.*; |
| 6 | + |
| 7 | +@Command(name = "directories", mixinStandardHelpOptions = true, version = "20") |
| 8 | +public class DirectoriesCli implements Runnable { |
| 9 | + @Option(names = {"--cache"}, description = "Prints cache directory") |
| 10 | + boolean cache; |
| 11 | + @Option(names = {"--config"}, description = "Prints config directory") |
| 12 | + boolean config; |
| 13 | + @Option(names = {"--data"}, description = "Prints data directory") |
| 14 | + boolean data; |
| 15 | + @Option(names = {"--data-local"}, description = "Prints local data directory") |
| 16 | + boolean dataLocal; |
| 17 | + @Option(names = {"--preferences"}, description = "Prints preferences directory") |
| 18 | + boolean preferences; |
| 19 | + @Option(names = {"--runtime"}, description = "Prints runtime directory") |
| 20 | + boolean runtime; |
| 21 | + |
| 22 | + @Parameters(index = "0") |
| 23 | + String project; |
| 24 | + |
| 25 | + @Override |
| 26 | + public void run() { |
| 27 | + int dirCount = 0; |
| 28 | + if (cache) dirCount += 1; |
| 29 | + if (config) dirCount += 1; |
| 30 | + if (data) dirCount += 1; |
| 31 | + if (dataLocal) dirCount += 1; |
| 32 | + if (preferences) dirCount += 1; |
| 33 | + if (runtime) dirCount += 1; |
| 34 | + |
| 35 | + boolean all = dirCount == 0; |
| 36 | + |
| 37 | + ProjectDirectories projDirs = ProjectDirectories.from(null, null, project); |
| 38 | + |
| 39 | + if (dirCount == 1) { |
| 40 | + if (cache) |
| 41 | + System.out.println(projDirs.cacheDir); |
| 42 | + if (config) |
| 43 | + System.out.println(projDirs.configDir); |
| 44 | + if (data) |
| 45 | + System.out.println(projDirs.dataDir); |
| 46 | + if (dataLocal) |
| 47 | + System.out.println(projDirs.dataLocalDir); |
| 48 | + if (preferences) |
| 49 | + System.out.println(projDirs.preferenceDir); |
| 50 | + if (runtime) |
| 51 | + System.out.println(projDirs.runtimeDir); |
| 52 | + } else { |
| 53 | + if (all || cache) |
| 54 | + System.out.println("cache: " + projDirs.cacheDir); |
| 55 | + if (all || config) |
| 56 | + System.out.println("config: " + projDirs.configDir); |
| 57 | + if (all || data) |
| 58 | + System.out.println("data: " + projDirs.dataDir); |
| 59 | + if (all || dataLocal) |
| 60 | + System.out.println("local data: " + projDirs.dataLocalDir); |
| 61 | + if (all || preferences) |
| 62 | + System.out.println("preference: " + projDirs.preferenceDir); |
| 63 | + if (all || runtime) |
| 64 | + System.out.println("runtime: " + projDirs.runtimeDir); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public static void main(String... args) { |
| 69 | + System.exit(new CommandLine(new DirectoriesCli()).execute(args)); |
| 70 | + } |
| 71 | +} |
0 commit comments