Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 8df3a00

Browse files
Add cli module
1 parent 7a92c6f commit 8df3a00

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

build.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@ lazy val core = project
5353
testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a")),
5454
automaticModuleName("dev.dirs")
5555
)
56+
57+
lazy val cli = project
58+
.dependsOn(core)
59+
.settings(
60+
sharedSettings,
61+
name := "directories-cli",
62+
libraryDependencies += "info.picocli" % "picocli" % "4.4.0",
63+
automaticModuleName("dev.dirs.cli")
64+
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)