Compare commits
No commits in common. "master" and "ae13ce049f0861644f3ab516be454fd43f0856e6" have entirely different histories.
master
...
ae13ce049f
19 changed files with 178 additions and 459 deletions
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
@ -1 +0,0 @@
|
||||||
* @jotoho
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -31,12 +31,12 @@ hs_err_pid*
|
||||||
build
|
build
|
||||||
|
|
||||||
# Ignore gradle wrapper
|
# Ignore gradle wrapper
|
||||||
gradlew
|
/gradle
|
||||||
gradlew.bat
|
/gradlew
|
||||||
|
/gradlew.bat
|
||||||
|
|
||||||
# Ignore manual compilation results
|
# Ignore manual compilation results
|
||||||
/de/jotoho/
|
/de/jotoho/
|
||||||
/META-INF
|
/META-INF
|
||||||
/.idea/*
|
/.idea
|
||||||
!/.idea/codeStyles/
|
|
||||||
*.zst
|
*.zst
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<option name="LINE_SEPARATOR" value=" " />
|
|
||||||
<option name="RIGHT_MARGIN" value="100" />
|
|
||||||
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
|
|
||||||
<option name="ENABLE_SECOND_REFORMAT" value="true" />
|
|
||||||
<option name="SOFT_MARGINS" value="80" />
|
|
||||||
<JavaCodeStyleSettings>
|
|
||||||
<option name="ANNOTATION_PARAMETER_WRAP" value="5" />
|
|
||||||
<option name="ALIGN_MULTILINE_ANNOTATION_PARAMETERS" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_TEXT_BLOCKS" value="true" />
|
|
||||||
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
|
|
||||||
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
|
|
||||||
<option name="JD_P_AT_EMPTY_LINES" value="false" />
|
|
||||||
<option name="JD_KEEP_INVALID_TAGS" value="false" />
|
|
||||||
<option name="JD_KEEP_EMPTY_LINES" value="false" />
|
|
||||||
<option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" />
|
|
||||||
<option name="JD_PARAM_DESCRIPTION_ON_NEW_LINE" value="true" />
|
|
||||||
</JavaCodeStyleSettings>
|
|
||||||
<JetCodeStyleSettings>
|
|
||||||
<option name="CONTINUATION_INDENT_IN_PARAMETER_LISTS" value="false" />
|
|
||||||
<option name="CONTINUATION_INDENT_IN_ARGUMENT_LISTS" value="false" />
|
|
||||||
<option name="CONTINUATION_INDENT_FOR_CHAINED_CALLS" value="false" />
|
|
||||||
<option name="CONTINUATION_INDENT_IN_SUPERTYPE_LISTS" value="false" />
|
|
||||||
<option name="WRAP_EXPRESSION_BODY_FUNCTIONS" value="1" />
|
|
||||||
</JetCodeStyleSettings>
|
|
||||||
<codeStyleSettings language="JAVA">
|
|
||||||
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
|
|
||||||
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
|
|
||||||
<option name="KEEP_BLANK_LINES_BETWEEN_PACKAGE_DECLARATION_AND_HEADER" value="0" />
|
|
||||||
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
|
|
||||||
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_ASSIGNMENT" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_THROWS_LIST" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
|
|
||||||
<option name="CALL_PARAMETERS_WRAP" value="5" />
|
|
||||||
<option name="METHOD_PARAMETERS_WRAP" value="5" />
|
|
||||||
<option name="RESOURCE_LIST_WRAP" value="5" />
|
|
||||||
<option name="EXTENDS_LIST_WRAP" value="1" />
|
|
||||||
<option name="THROWS_LIST_WRAP" value="1" />
|
|
||||||
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
|
|
||||||
<option name="THROWS_KEYWORD_WRAP" value="1" />
|
|
||||||
<option name="METHOD_CALL_CHAIN_WRAP" value="2" />
|
|
||||||
<option name="BINARY_OPERATION_WRAP" value="1" />
|
|
||||||
<option name="TERNARY_OPERATION_WRAP" value="5" />
|
|
||||||
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
|
|
||||||
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
|
|
||||||
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
|
|
||||||
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
|
|
||||||
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
|
|
||||||
<option name="FOR_STATEMENT_WRAP" value="5" />
|
|
||||||
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
|
|
||||||
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
|
|
||||||
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
|
|
||||||
<option name="ASSIGNMENT_WRAP" value="1" />
|
|
||||||
<option name="WRAP_COMMENTS" value="true" />
|
|
||||||
<option name="ASSERT_STATEMENT_WRAP" value="1" />
|
|
||||||
<option name="WRAP_LONG_LINES" value="true" />
|
|
||||||
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
|
|
||||||
<option name="VARIABLE_ANNOTATION_WRAP" value="5" />
|
|
||||||
<option name="ENUM_CONSTANTS_WRAP" value="5" />
|
|
||||||
<option name="KEEP_BUILDER_METHODS_INDENTS" value="true" />
|
|
||||||
<indentOptions>
|
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
|
||||||
</indentOptions>
|
|
||||||
</codeStyleSettings>
|
|
||||||
<codeStyleSettings language="kotlin">
|
|
||||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
|
||||||
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
|
|
||||||
<option name="CALL_PARAMETERS_WRAP" value="5" />
|
|
||||||
<option name="METHOD_PARAMETERS_WRAP" value="5" />
|
|
||||||
<option name="EXTENDS_LIST_WRAP" value="5" />
|
|
||||||
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
|
|
||||||
<option name="ASSIGNMENT_WRAP" value="5" />
|
|
||||||
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
|
|
||||||
<option name="VARIABLE_ANNOTATION_WRAP" value="5" />
|
|
||||||
<option name="ENUM_CONSTANTS_WRAP" value="5" />
|
|
||||||
</codeStyleSettings>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
|
@ -1,5 +0,0 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<state>
|
|
||||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
|
||||||
</state>
|
|
||||||
</component>
|
|
16
AUTHORS.md
16
AUTHORS.md
|
@ -1,16 +0,0 @@
|
||||||
# waituntil Contributors / Authors
|
|
||||||
|
|
||||||
By adding their names to this document, contributors agree to license all of their
|
|
||||||
contributions and patches to the waituntil project [under the AGPL version 3 or later.](./LICENSE.md)
|
|
||||||
|
|
||||||
Contributors may choose to supply either their complete legal name, online pseudonym or both.
|
|
||||||
At least one is required.
|
|
||||||
|
|
||||||
The email, website and notes fields are optional but contributors are encouraged
|
|
||||||
to supply at least one reliable method of communication.
|
|
||||||
|
|
||||||
## Maintainer(s)
|
|
||||||
|
|
||||||
| full name | pseudonym | email | website | notes |
|
|
||||||
|-|:-:|-:|-:|-|
|
|
||||||
| Jonas Tobias Hopusch | jotoho | [contact@jotoho.de](mailto:contact@jotoho.de) | [www.jotoho.de](https://www.jotoho.de/) | original creator |
|
|
30
README.md
30
README.md
|
@ -1,38 +1,12 @@
|
||||||
# waituntil
|
# waituntil
|
||||||
|
|
||||||
A basic tool for delaying work in the terminal to a specific time. This software was originally
|
This simple tool doubles as a programming exercise for me, as I attempt to learn Kotlin from my perspective as a Java developer and a (hopefully) useful tool for personal use. I will expand this README with details as the project evolves.
|
||||||
written in Kotlin and then recently ported to Java.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
java -jar ./waituntil.jar 10:30 ; reboot # Replace reboot with your command
|
|
||||||
```
|
|
||||||
|
|
||||||
The example above would make the program wait until half past ten AM before exiting and allowing
|
|
||||||
the next command to run. The timestamp can be passed in the formats `HH:MM` or `HH:MM:SS` and must
|
|
||||||
be in the 24-hour system. Passing dates is not supported but entering a time that has already passed
|
|
||||||
will make the software wait until that time on the following day.
|
|
||||||
|
|
||||||
## Contributing / Submitting Feedback
|
|
||||||
|
|
||||||
The [canonical home of this project](https://gitea.jotoho.de/jotoho/waituntil/) is
|
|
||||||
[on my personal Gitea-instance](https://gitea.jotoho.de/) but since it has registration
|
|
||||||
turned off, collaborating there is difficult.
|
|
||||||
|
|
||||||
If you have not been given an account on [gitea.jotoho.de](https://gitea.jotoho.de/)
|
|
||||||
then you can alternatively send me feedback, bug reports or patches [via email to
|
|
||||||
contact@jotoho.de](mailto:contact@jotoho.de).
|
|
||||||
Should that fail, there may be alternative ways to contact me listed on
|
|
||||||
[my personal website.](https://www.jotoho.de/)
|
|
||||||
|
|
||||||
In the future, I may also decide to create a mirror for this project on GitHub, gitlab.com or similar.
|
|
||||||
|
|
||||||
## Copyright / Licensing
|
## Copyright / Licensing
|
||||||
|
|
||||||
```
|
```
|
||||||
waituntil - a tool for delaying command execution until the specified time
|
waituntil - a tool for delaying command execution until the specified time
|
||||||
Copyright (C) 2022 Jonas Tobias Hopusch
|
Copyright (C) 2021 Jonas Tobias Hopusch
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Affero General Public License as
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
|
|
@ -1,53 +1,62 @@
|
||||||
import java.io.ByteArrayOutputStream
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import java.io.OutputStream
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
|
||||||
|
kotlin("jvm") version "latest.release"
|
||||||
|
|
||||||
// Apply the application plugin to add support for building a CLI application in Java.
|
// Apply the application plugin to add support for building a CLI application in Java.
|
||||||
application
|
application
|
||||||
java
|
|
||||||
|
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
// For generating fat jars
|
||||||
|
id("com.github.johnrengelman.shadow") version "latest.release"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group = "de.jotoho"
|
||||||
|
version = "0.1.1"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// Use Maven Central for resolving dependencies.
|
// Use Maven Central for resolving dependencies.
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(group = "commons-cli", name = "commons-cli", version = "1.5.0")
|
// Align versions of all Kotlin components
|
||||||
}
|
implementation(platform(kotlin("bom", "latest.release")))
|
||||||
|
|
||||||
fun versionBanner(): String {
|
// Use the Kotlin standard library.
|
||||||
val os = ByteArrayOutputStream()
|
implementation(kotlin("stdlib", "latest.release"))
|
||||||
project.exec {
|
|
||||||
commandLine = "git describe --tags --always --dirty --abbrev".split(" ")
|
|
||||||
standardOutput = os
|
|
||||||
errorOutput = OutputStream.nullOutputStream()
|
|
||||||
}
|
|
||||||
return String(os.toByteArray()).trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "de.jotoho"
|
// Use the Kotlin test library.
|
||||||
version = versionBanner()
|
testImplementation(kotlin("test", "latest.release"))
|
||||||
|
|
||||||
|
// Use the Kotlin JUnit integration.
|
||||||
|
testImplementation(kotlin("test-junit", "latest.release"))
|
||||||
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_16
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_16
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.jar {
|
tasks.jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes("Implementation-Title" to project.name,
|
attributes(
|
||||||
"Implementation-Version" to project.version,
|
"Implementation-Title" to "waituntil",
|
||||||
"Main-Class" to "de.jotoho.waituntil.Main"
|
"Implementation-Version" to "${project.version}",
|
||||||
//"Main-Module" to "de.jotoho.waituntil.main"
|
"Main-Class" to "de.jotoho.waituntil.StartKt"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions.jvmTarget = "16"
|
||||||
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
// Define the main class for the application.
|
// Define the main class for the application.
|
||||||
mainClass.set("de.jotoho.waituntil.Main")
|
mainClass.set("de.jotoho.waituntil.StartKt")
|
||||||
//mainModule.set("de.jotoho.waituntil.main")
|
|
||||||
}
|
}
|
||||||
|
|
5
compile.sh
Executable file
5
compile.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# shellcheck disable=SC2046
|
||||||
|
# Word splitting in find results is intentional!
|
||||||
|
kotlinc $(find src/main -type f -iname '*.kt') -jvm-target 16 -include-runtime -d waituntil.jar
|
|
@ -1 +1,2 @@
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
kotlin.code.style=official
|
||||||
|
|
1
gradle/wrapper/gradle-wrapper.properties
vendored
1
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1 +0,0 @@
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
|
|
3
run.sh
Executable file
3
run.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
java -jar waituntil.jar $*
|
|
@ -1,39 +0,0 @@
|
||||||
package de.jotoho.waituntil;
|
|
||||||
|
|
||||||
/*
|
|
||||||
waituntil - a tool for delaying command execution until the specified time
|
|
||||||
Copyright (C) 2022 Jonas Tobias Hopusch
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.apache.commons.cli.Option;
|
|
||||||
import org.apache.commons.cli.Options;
|
|
||||||
|
|
||||||
final class AppOptions {
|
|
||||||
public final Option help = Option.builder()
|
|
||||||
.argName("h")
|
|
||||||
.longOpt("help")
|
|
||||||
.desc("Shows this help message and exits")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
public final Option version = Option.builder()
|
|
||||||
.argName("v")
|
|
||||||
.longOpt("version")
|
|
||||||
.desc("Shows version information and exits")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
public final Options options = new Options().addOption(help)
|
|
||||||
.addOption(version);
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package de.jotoho.waituntil;
|
|
||||||
|
|
||||||
/*
|
|
||||||
waituntil - a tool for delaying command execution until the specified time
|
|
||||||
Copyright (C) 2022 Jonas Tobias Hopusch
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public record GlobalConf() {
|
|
||||||
public static final String langGerman = "de";
|
|
||||||
public static final String applicationOutputLanguage = (Locale.getDefault()
|
|
||||||
.getLanguage()
|
|
||||||
.equals(Locale.GERMAN.getLanguage()))
|
|
||||||
? Locale.GERMAN.getLanguage()
|
|
||||||
: Locale.ENGLISH.getLanguage();
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
package de.jotoho.waituntil;
|
|
||||||
|
|
||||||
/*
|
|
||||||
waituntil - a tool for delaying command execution until the specified time
|
|
||||||
Copyright (C) 2022 Jonas Tobias Hopusch
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
|
||||||
import org.apache.commons.cli.DefaultParser;
|
|
||||||
import org.apache.commons.cli.Options;
|
|
||||||
import org.apache.commons.cli.ParseException;
|
|
||||||
|
|
||||||
import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage;
|
|
||||||
import static java.lang.System.Logger.Level;
|
|
||||||
|
|
||||||
// This file contains the main function and other utility function necessary
|
|
||||||
// for interpreting the terminal arguments.
|
|
||||||
// See README.md and LICENSE.md for license information
|
|
||||||
// Author: Jonas Tobias Hopusch (@jotoho)
|
|
||||||
|
|
||||||
public final class Main {
|
|
||||||
private static final System.Logger logger = System.getLogger("main");
|
|
||||||
|
|
||||||
private static void printVersionInformation() {
|
|
||||||
final var thisPackage = Main.class.getPackage();
|
|
||||||
final var appVersion = thisPackage.getImplementationVersion() != null
|
|
||||||
? thisPackage.getImplementationVersion()
|
|
||||||
: "version unknown";
|
|
||||||
|
|
||||||
System.out.println("waituntil " + appVersion);
|
|
||||||
System.out.println("""
|
|
||||||
Project Repository: https://gitea.jotoho.de/jotoho/waituntil
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the
|
|
||||||
GNU General Public License as published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
See the GNU General Public License for more details.""");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void printHelpInformation() {
|
|
||||||
switch (applicationOutputLanguage) {
|
|
||||||
case GlobalConf.langGerman -> logger.log(Level.ERROR,
|
|
||||||
"Hilfe kommt noch. (Nicht " +
|
|
||||||
"implementiert)");
|
|
||||||
default -> logger.log(Level.ERROR, "Help is yet to come. (Not implemented)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CommandLine parseArgs(final Options options, final String[] args)
|
|
||||||
throws ParseException {
|
|
||||||
return DefaultParser.builder()
|
|
||||||
.setStripLeadingAndTrailingQuotes(true)
|
|
||||||
.build()
|
|
||||||
.parse(options, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized static void main(final String[] args) {
|
|
||||||
// Retrieve defined CLI options
|
|
||||||
final var appOptions = new AppOptions();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Parse CLI
|
|
||||||
final var parsedArguments = parseArgs(appOptions.options, args);
|
|
||||||
final var userData = parsedArguments.getArgs();
|
|
||||||
|
|
||||||
// Differentiate between usage scenarios
|
|
||||||
if (parsedArguments.hasOption(appOptions.help)) {
|
|
||||||
printHelpInformation();
|
|
||||||
} else if (parsedArguments.hasOption(appOptions.version)) {
|
|
||||||
printVersionInformation();
|
|
||||||
} else if (userData.length == 0) {
|
|
||||||
switch (applicationOutputLanguage) {
|
|
||||||
case GlobalConf.langGerman -> logger.log(Level.ERROR,
|
|
||||||
"Es wurde keine Uhrzeit " +
|
|
||||||
"angegeben.");
|
|
||||||
default -> logger.log(Level.ERROR, "No target time was provided.");
|
|
||||||
}
|
|
||||||
System.exit(1);
|
|
||||||
} else if (userData.length > 1) {
|
|
||||||
switch (applicationOutputLanguage) {
|
|
||||||
case GlobalConf.langGerman -> logger.log(Level.ERROR,
|
|
||||||
"Zu viele Argumente " +
|
|
||||||
"wurden angegeben.");
|
|
||||||
default -> logger.log(Level.ERROR, "Too many arguments provided.");
|
|
||||||
}
|
|
||||||
System.exit(1);
|
|
||||||
} else {
|
|
||||||
final var target = TimeCalculator.calculateAndAnnounceTargetTime(userData[0]);
|
|
||||||
Sleep.waitUntilTimeStamp(target);
|
|
||||||
}
|
|
||||||
} catch (final ParseException e) {
|
|
||||||
System.getLogger("main")
|
|
||||||
.log(Level.ERROR,
|
|
||||||
"Parsing of arguments failed and the program cannot continue.",
|
|
||||||
e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
package de.jotoho.waituntil;
|
|
||||||
|
|
||||||
/*
|
|
||||||
waituntil - a tool for delaying command execution until the specified time
|
|
||||||
Copyright (C) 2022 Jonas Tobias Hopusch
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.time.format.FormatStyle;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import static java.lang.System.Logger.Level;
|
|
||||||
|
|
||||||
public final class Sleep {
|
|
||||||
public static void waitUntilTimeStamp(ZonedDateTime timestamp) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(Math.max(0,
|
|
||||||
Instant.now()
|
|
||||||
.until(timestamp, ChronoUnit.MILLIS)));
|
|
||||||
} catch (final InterruptedException ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
final String formattedTimeStamp = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
|
||||||
.withZone(TimeZone.getDefault()
|
|
||||||
.toZoneId())
|
|
||||||
.format(Instant.now());
|
|
||||||
|
|
||||||
final String msg = switch (GlobalConf.applicationOutputLanguage) {
|
|
||||||
case GlobalConf.langGerman -> "Erfolgreich bis %s gewartet!";
|
|
||||||
default -> "Successfully waited until %s";
|
|
||||||
};
|
|
||||||
|
|
||||||
final String msgWithData = msg.formatted(formattedTimeStamp);
|
|
||||||
System.getLogger("sleep")
|
|
||||||
.log(Level.INFO, msgWithData);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
package de.jotoho.waituntil;
|
|
||||||
|
|
||||||
/*
|
|
||||||
waituntil - a tool for delaying command execution until the specified time
|
|
||||||
Copyright (C) 2022 Jonas Tobias Hopusch
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of the
|
|
||||||
License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.time.format.FormatStyle;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import static java.lang.System.Logger.Level;
|
|
||||||
|
|
||||||
public final class TimeCalculator {
|
|
||||||
|
|
||||||
public static ZonedDateTime calculateAndAnnounceTargetTime(final String userTimeInputRaw) {
|
|
||||||
final var userTimeInputRelative = LocalTime.parse(userTimeInputRaw);
|
|
||||||
final var userTimeInputAbsolute = ZonedDateTime.of(LocalDate.now(),
|
|
||||||
userTimeInputRelative,
|
|
||||||
TimeZone.getDefault()
|
|
||||||
.toZoneId());
|
|
||||||
|
|
||||||
final var userTimeInputFinal = (Instant.now()
|
|
||||||
.isBefore(userTimeInputAbsolute.toInstant()))
|
|
||||||
? userTimeInputAbsolute
|
|
||||||
: userTimeInputAbsolute.plusDays(1);
|
|
||||||
|
|
||||||
final var formattedTimeStamp =
|
|
||||||
userTimeInputFinal.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG));
|
|
||||||
|
|
||||||
final String msg = switch (GlobalConf.applicationOutputLanguage) {
|
|
||||||
case GlobalConf.langGerman -> ("Dieses Program wird bis zum %s warten.").formatted(
|
|
||||||
formattedTimeStamp);
|
|
||||||
default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp);
|
|
||||||
};
|
|
||||||
System.getLogger("timecalculator")
|
|
||||||
.log(Level.INFO, msg);
|
|
||||||
|
|
||||||
return userTimeInputFinal;
|
|
||||||
}
|
|
||||||
}
|
|
64
src/main/kotlin/de/jotoho/waituntil/Start.kt
Normal file
64
src/main/kotlin/de/jotoho/waituntil/Start.kt
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package de.jotoho.waituntil
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
// This file contains the main function and other utility function necessary for interpreting the terminal arguments.
|
||||||
|
// See README.md and LICENSE.md for license information
|
||||||
|
// Author: Jonas Tobias Hopusch (@jotoho)
|
||||||
|
|
||||||
|
|
||||||
|
val langGerman: String = Locale.GERMAN.language
|
||||||
|
val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language))
|
||||||
|
Locale.GERMAN.language
|
||||||
|
else Locale.ENGLISH.language
|
||||||
|
|
||||||
|
// For accessing package information
|
||||||
|
object DummyClass
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val optionDictionary = mapOf(Pair("-h", "--help"), Pair("-v", "--version"))
|
||||||
|
|
||||||
|
val options = HashSet<String>()
|
||||||
|
val words = HashSet<String>()
|
||||||
|
|
||||||
|
for (arg in args) {
|
||||||
|
if (arg.startsWith("--")) {
|
||||||
|
options.add(arg.substring(startIndex = 2))
|
||||||
|
} else if (arg.startsWith('-')) {
|
||||||
|
if (optionDictionary.containsKey(arg))
|
||||||
|
options.add(optionDictionary[arg]!!.substring(startIndex = 2))
|
||||||
|
else
|
||||||
|
System.err.println("Short-hand '$arg' does not exist. Ignoring!")
|
||||||
|
} else
|
||||||
|
words.add(arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.contains("help")) {
|
||||||
|
when (applicationOutputLanguage) {
|
||||||
|
langGerman -> println("Hilfe kommt noch. (Nicht implementiert)")
|
||||||
|
else -> {
|
||||||
|
println("Help is yet to come. (Not implemented)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (options.contains("version")) {
|
||||||
|
when (applicationOutputLanguage) {
|
||||||
|
langGerman -> {
|
||||||
|
val thisPackage = DummyClass.javaClass.`package`
|
||||||
|
val appVersion = thisPackage.implementationVersion ?: "UNKNOWN"
|
||||||
|
println("waituntil version $appVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (words.size == 1) {
|
||||||
|
val target = calculateAndAnnounceTargetTime(words.iterator().next())
|
||||||
|
waitUntilTimeStamp(target)
|
||||||
|
} else {
|
||||||
|
when (applicationOutputLanguage) {
|
||||||
|
langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)")
|
||||||
|
else -> {
|
||||||
|
System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exitProcess(1)
|
||||||
|
}
|
||||||
|
}
|
24
src/main/kotlin/de/jotoho/waituntil/sleeping.kt
Normal file
24
src/main/kotlin/de/jotoho/waituntil/sleeping.kt
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package de.jotoho.waituntil
|
||||||
|
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.ZonedDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
import java.time.format.FormatStyle
|
||||||
|
import java.time.temporal.ChronoUnit
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun waitUntilTimeStamp(timestamp: ZonedDateTime) {
|
||||||
|
Thread.sleep(Instant.now().until(timestamp, ChronoUnit.MILLIS).coerceAtLeast(0))
|
||||||
|
|
||||||
|
val formattedTimeStamp: String =
|
||||||
|
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||||
|
.withZone(TimeZone.getDefault().toZoneId())
|
||||||
|
.format(Instant.now())
|
||||||
|
|
||||||
|
when (applicationOutputLanguage) {
|
||||||
|
langGerman -> System.err.println("Erfolgreich bis $formattedTimeStamp gewartet!")
|
||||||
|
else -> {
|
||||||
|
System.err.println("Successfully waited until $formattedTimeStamp")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
src/main/kotlin/de/jotoho/waituntil/timecalc.kt
Normal file
41
src/main/kotlin/de/jotoho/waituntil/timecalc.kt
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package de.jotoho.waituntil
|
||||||
|
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.LocalTime
|
||||||
|
import java.time.ZonedDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
import java.time.format.FormatStyle
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime {
|
||||||
|
val userTimeInputRelative = LocalTime.parse(userTimeInputRaw)
|
||||||
|
val userTimeInputAbsolute =
|
||||||
|
ZonedDateTime.of(
|
||||||
|
LocalDate.now(),
|
||||||
|
userTimeInputRelative,
|
||||||
|
TimeZone.getDefault().toZoneId()
|
||||||
|
)
|
||||||
|
|
||||||
|
val userTimeInputFinal =
|
||||||
|
if (Instant.now().isBefore(userTimeInputAbsolute.toInstant()))
|
||||||
|
userTimeInputAbsolute
|
||||||
|
else userTimeInputAbsolute.plusDays(1)
|
||||||
|
|
||||||
|
val formattedTimeStamp =
|
||||||
|
userTimeInputFinal.format(
|
||||||
|
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
|
||||||
|
)
|
||||||
|
|
||||||
|
when (applicationOutputLanguage) {
|
||||||
|
langGerman ->
|
||||||
|
System.err.println(
|
||||||
|
"Dieses Program wird bis zum $formattedTimeStamp warten."
|
||||||
|
)
|
||||||
|
else -> {
|
||||||
|
println("WaitUntil will suspend until $formattedTimeStamp")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return userTimeInputFinal
|
||||||
|
}
|
Loading…
Reference in a new issue