-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CLI #39
Open
alexarchambault
wants to merge
2
commits into
dirs-dev:main
Choose a base branch
from
alexarchambault:cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add CLI #39
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,64 @@ | ||
lazy val root = (project in file(".")) | ||
lazy val sharedSettings = Def.settings( | ||
organization := "dev.dirs", | ||
managedScalaInstance := false, | ||
crossPaths := false, | ||
version := "20", | ||
homepage := Some(url("https://github.com/dirs-dev/directories-jvm")), | ||
licenses := Seq("Mozilla Public License 2.0" -> url("https://opensource.org/licenses/MPL-2.0")), | ||
fork := true, | ||
// The javaHome setting can be removed if building against the latest installed version of Java is acceptable. | ||
// Running the tests requires removing the setting. | ||
// It can also be changed to point to a different Java version. | ||
// javaHome := Some(file("/home/soc/apps/zulu6.19.0.1-jdk6.0.103-linux_x64/")), | ||
/* | ||
publishTo := { | ||
val nexus = "https://oss.sonatype.org/" | ||
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots") | ||
else Some("releases" at nexus + "service/local/staging/deploy/maven2") | ||
}, | ||
*/ | ||
pomIncludeRepository := { _ => false }, | ||
pomExtra := | ||
<scm> | ||
<url>[email protected]:dirs-dev/directories-jvm.git</url> | ||
<connection>scm:git:[email protected]:dirs-dev/directories-jvm.git</connection> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>soc</id> | ||
<name>Simon Ochsenreither</name> | ||
<url>https://github.com/soc</url> | ||
<roles> | ||
<role>Project Lead</role> | ||
</roles> | ||
</developer> | ||
</developers> | ||
) | ||
|
||
def automaticModuleName(name: String) = Def.settings( | ||
packageOptions in (Compile, packageBin) += { | ||
import java.util.jar.{Attributes, Manifest} | ||
val manifest = new Manifest | ||
manifest.getMainAttributes.put(new Attributes.Name("Automatic-Module-Name"), name) | ||
Package.JarManifest(manifest) | ||
} | ||
) | ||
|
||
lazy val core = project | ||
.settings( | ||
sharedSettings, | ||
name := "directories", | ||
organization := "dev.dirs", | ||
managedScalaInstance := false, | ||
crossPaths := false, | ||
version := "20", | ||
homepage := Some(url("https://github.com/dirs-dev/directories-jvm")), | ||
licenses := Seq("Mozilla Public License 2.0" -> url("https://opensource.org/licenses/MPL-2.0")), | ||
fork := true, | ||
// The javaHome setting can be removed if building against the latest installed version of Java is acceptable. | ||
// Running the tests requires removing the setting. | ||
// It can also be changed to point to a different Java version. | ||
// javaHome := Some(file("/home/soc/apps/zulu6.19.0.1-jdk6.0.103-linux_x64/")), | ||
libraryDependencies += "junit" % "junit" % "4.13" % Test, | ||
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test, | ||
testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a")), | ||
/* | ||
publishTo := { | ||
val nexus = "https://oss.sonatype.org/" | ||
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots") | ||
else Some("releases" at nexus + "service/local/staging/deploy/maven2") | ||
}, | ||
*/ | ||
packageOptions in (Compile, packageBin) += { | ||
import java.util.jar.{Attributes, Manifest} | ||
val manifest = new Manifest | ||
manifest.getMainAttributes.put(new Attributes.Name("Automatic-Module-Name"), "dev.dirs") | ||
Package.JarManifest(manifest) | ||
}, | ||
pomIncludeRepository := { _ => false }, | ||
pomExtra := | ||
<scm> | ||
<url>[email protected]:dirs-dev/directories-jvm.git</url> | ||
<connection>scm:git:[email protected]:dirs-dev/directories-jvm.git</connection> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>soc</id> | ||
<name>Simon Ochsenreither</name> | ||
<url>https://github.com/soc</url> | ||
<roles> | ||
<role>Project Lead</role> | ||
</roles> | ||
</developer> | ||
</developers> | ||
automaticModuleName("dev.dirs") | ||
) | ||
|
||
lazy val cli = project | ||
.dependsOn(core) | ||
.settings( | ||
sharedSettings, | ||
name := "directories-cli", | ||
libraryDependencies += "info.picocli" % "picocli" % "4.4.0", | ||
automaticModuleName("dev.dirs.cli") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package dev.dirs.cli; | ||
|
||
import dev.dirs.ProjectDirectories; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.*; | ||
|
||
@Command(name = "directories", mixinStandardHelpOptions = true, version = "20") | ||
public class DirectoriesCli implements Runnable { | ||
@Option(names = {"--cache"}, description = "Prints cache directory") | ||
boolean cache; | ||
@Option(names = {"--config"}, description = "Prints config directory") | ||
boolean config; | ||
@Option(names = {"--data"}, description = "Prints data directory") | ||
boolean data; | ||
@Option(names = {"--data-local"}, description = "Prints local data directory") | ||
boolean dataLocal; | ||
@Option(names = {"--preferences"}, description = "Prints preferences directory") | ||
boolean preferences; | ||
@Option(names = {"--runtime"}, description = "Prints runtime directory") | ||
boolean runtime; | ||
|
||
@Parameters(index = "0") | ||
String project; | ||
|
||
@Override | ||
public void run() { | ||
int dirCount = 0; | ||
if (cache) dirCount += 1; | ||
if (config) dirCount += 1; | ||
if (data) dirCount += 1; | ||
if (dataLocal) dirCount += 1; | ||
if (preferences) dirCount += 1; | ||
if (runtime) dirCount += 1; | ||
|
||
boolean all = dirCount == 0; | ||
|
||
ProjectDirectories projDirs = ProjectDirectories.from(null, null, project); | ||
|
||
if (dirCount == 1) { | ||
if (cache) | ||
System.out.println(projDirs.cacheDir); | ||
if (config) | ||
System.out.println(projDirs.configDir); | ||
if (data) | ||
System.out.println(projDirs.dataDir); | ||
if (dataLocal) | ||
System.out.println(projDirs.dataLocalDir); | ||
if (preferences) | ||
System.out.println(projDirs.preferenceDir); | ||
if (runtime) | ||
System.out.println(projDirs.runtimeDir); | ||
} else { | ||
if (all || cache) | ||
System.out.println("cache: " + projDirs.cacheDir); | ||
if (all || config) | ||
System.out.println("config: " + projDirs.configDir); | ||
if (all || data) | ||
System.out.println("data: " + projDirs.dataDir); | ||
if (all || dataLocal) | ||
System.out.println("local data: " + projDirs.dataLocalDir); | ||
if (all || preferences) | ||
System.out.println("preference: " + projDirs.preferenceDir); | ||
if (all || runtime) | ||
System.out.println("runtime: " + projDirs.runtimeDir); | ||
} | ||
} | ||
|
||
public static void main(String... args) { | ||
System.exit(new CommandLine(new DirectoriesCli()).execute(args)); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!