-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a command line tool skeleton (#324)
- Loading branch information
1 parent
f8e927a
commit b4c9c41
Showing
6 changed files
with
241 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/logs/ |
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,25 @@ | ||
plugins { | ||
application | ||
|
||
alias(libs.plugins.spring.boot) | ||
alias(libs.plugins.spring.dependency.management) | ||
} | ||
|
||
application { | ||
applicationName = "hcc-cli" | ||
mainClass.set("com.homeclimatecontrol.hcc.cli.HccCLI") | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.jcommander) | ||
implementation(libs.springboot.starter) | ||
implementation(libs.springboot.starter.log4j2) | ||
implementation(libs.springboot.starter.rsocket) | ||
} | ||
|
||
configurations { | ||
all { | ||
exclude("org.springframework.boot", "spring-boot-starter-logging") | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
app/hcc-cli/src/main/java/com/homeclimatecontrol/hcc/cli/HccCLI.java
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,90 @@ | ||
package com.homeclimatecontrol.hcc.cli; | ||
|
||
import com.beust.jcommander.JCommander; | ||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.ParameterException; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.ThreadContext; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
|
||
@SpringBootApplication | ||
public class HccCLI implements CommandLineRunner { | ||
|
||
private static final Logger logger = LogManager.getLogger(HccCLI.class); | ||
|
||
private static final String COMMAND_GET_META = "get-meta"; | ||
|
||
public abstract class CommandBase { | ||
|
||
@Parameter(names = { "--url" }, description = "URL to connect to", required = true) | ||
String url; | ||
} | ||
|
||
public class CommandGetMeta extends CommandBase { | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
var builder = new SpringApplicationBuilder(HccCLI.class); | ||
|
||
builder.headless(false); | ||
|
||
var context = builder.run(args); | ||
|
||
context.close(); | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
|
||
var commandGetMeta = new CommandGetMeta(); | ||
var jc = JCommander | ||
.newBuilder() | ||
.addCommand(COMMAND_GET_META, commandGetMeta) | ||
.build(); | ||
|
||
try { | ||
|
||
jc.parse(args); | ||
|
||
if (jc.getParsedCommand() == null) { | ||
terminate(jc, "Please specify exactly one command", null); | ||
} | ||
|
||
switch (jc.getParsedCommand()) { | ||
|
||
case COMMAND_GET_META -> getMeta(commandGetMeta.url); | ||
|
||
} | ||
|
||
} catch (ParameterException ex) { | ||
|
||
terminate(jc, "Invalid command line arguments", ex); | ||
|
||
} catch (Throwable t) { | ||
|
||
terminate(jc, "Unhandled exception, terminating", t); | ||
} | ||
} | ||
|
||
private void getMeta(String url) { | ||
ThreadContext.push("getMeta"); | ||
try { | ||
logger.info("url={}", url); | ||
throw new UnsupportedOperationException("Stay tuned"); | ||
} finally { | ||
ThreadContext.pop(); | ||
} | ||
} | ||
|
||
private static void terminate(JCommander jc, String message, Throwable t) { | ||
|
||
logger.fatal(message, t); | ||
jc.usage(); | ||
System.exit(-1); | ||
} | ||
} |
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,118 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<Configuration status="WARN" monitorInterval="30"> | ||
<Properties> | ||
<Property name="logDir">logs</Property> | ||
</Properties> | ||
<Appenders> | ||
<Console name="ConsoleAppender" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%highlight{%d{HH:mm:ss,SSS} %level %class{1} %t %NDC %message%n}{TRACE=white}"/> | ||
<Filters> | ||
<!-- Set your comfortable debug level for the console. --> | ||
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/> | ||
</Filters> | ||
</Console> | ||
<RollingFile | ||
name="TraceAppender" | ||
fileName="${logDir}/dz-trace.log" | ||
filePattern="${logDir}/dz-trace.log.%d{yyyy-MM-dd}.gz"> | ||
<PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss,SSS} %level %class{1} %t %NDC %message%n}{TRACE=white}"/> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy interval="1"/> | ||
</Policies> | ||
<DefaultRolloverStrategy> | ||
<Delete basePath="${logDir}" maxDepth="2"> | ||
<IfFileName glob="dz-trace.log.*.gz" /> | ||
<!-- Trace level logs are HUGE --> | ||
<IfLastModified age="P1D" /> | ||
</Delete> | ||
</DefaultRolloverStrategy> | ||
<Filters> | ||
<ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/> | ||
</Filters> | ||
</RollingFile> | ||
<RollingFile | ||
name="DebugAppender" | ||
fileName="${logDir}/dz-debug.log" | ||
filePattern="${logDir}/dz-debug.log.%d{yyyy-MM-dd}.gz"> | ||
<PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss,SSS} %level %class{1} %t %NDC %message%n}"/> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy interval="1"/> | ||
</Policies> | ||
<DefaultRolloverStrategy> | ||
<Delete basePath="${logDir}" maxDepth="2"> | ||
<IfFileName glob="dz-debug.log.*.gz" /> | ||
<!-- Debug level logs are BIG --> | ||
<IfLastModified age="P7D" /> | ||
</Delete> | ||
</DefaultRolloverStrategy> | ||
<Filters> | ||
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/> | ||
</Filters> | ||
</RollingFile> | ||
<RollingFile | ||
name="InfoAppender" | ||
fileName="${logDir}/dz-info.log" | ||
filePattern="${logDir}/dz-info.log.%d{yyyy-MM-dd}.gz"> | ||
<PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss,SSS} %level %class{1} %t %NDC %message%n}"/> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy interval="1"/> | ||
</Policies> | ||
<DefaultRolloverStrategy> | ||
<Delete basePath="${logDir}" maxDepth="2"> | ||
<IfFileName glob="dz-info.log.*.gz" /> | ||
<!-- Debug level logs are BIG --> | ||
<IfLastModified age="P7D" /> | ||
</Delete> | ||
</DefaultRolloverStrategy> | ||
<Filters> | ||
<!-- Set your comfortable debug level for the debug log. Best be left as is.--> | ||
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/> | ||
</Filters> | ||
</RollingFile> | ||
<RollingFile | ||
name="WarnAppender" | ||
fileName="${logDir}/dz-warn.log" | ||
filePattern="${logDir}/dz-warn.log.%d{yyyy-MM-dd}.gz"> | ||
<PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss,SSS} %level %class{1} %t %NDC %message%n}"/> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy interval="1"/> | ||
</Policies> | ||
<DefaultRolloverStrategy> | ||
<Delete basePath="${logDir}" maxDepth="2"> | ||
<IfFileName glob="dz-warn.log.*.gz" /> | ||
<IfLastModified age="P30D" /> | ||
</Delete> | ||
</DefaultRolloverStrategy> | ||
<Filters> | ||
<!-- Set your comfortable debug level for the long term log. --> | ||
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/> | ||
</Filters> | ||
</RollingFile> | ||
|
||
</Appenders> | ||
<Loggers> | ||
<Logger name="net.sf.dz3r" level="debug" /> | ||
<Logger name="com.dalsemi" level="info" /> | ||
<Logger name="org.springframework" level="info" /> | ||
|
||
<!-- Reactive classes --> | ||
|
||
<Logger name="net.sf.dz3r" level="trace" /> | ||
|
||
<Root level="INFO"> | ||
|
||
<AppenderRef ref="ConsoleAppender"/> | ||
|
||
<!-- | ||
Uncomment the section below if you need extended diagnostics. | ||
WARNING: consumes a lot of disk space. | ||
--> | ||
<AppenderRef ref="TraceAppender"/> | ||
<AppenderRef ref="DebugAppender"/> | ||
|
||
<AppenderRef ref="InfoAppender"/> | ||
<AppenderRef ref="WarnAppender"/> | ||
|
||
</Root> | ||
</Loggers> | ||
</Configuration> |
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
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