Better cli usage messages.

This commit is contained in:
JesseBrault0709 2023-01-08 10:15:15 -06:00
parent a9bf55793a
commit 829ec4698e

View File

@ -17,8 +17,7 @@ import com.jessebrault.ssg.text.TextType
import org.apache.logging.log4j.Level import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
import org.apache.logging.log4j.core.config.Configuration import org.apache.logging.log4j.core.LoggerContext
import org.apache.logging.log4j.spi.LoggerContext
import picocli.CommandLine import picocli.CommandLine
import java.util.concurrent.Callable import java.util.concurrent.Callable
@ -33,22 +32,30 @@ class StaticSiteGeneratorCli implements Callable<Integer> {
private static final Logger logger = LogManager.getLogger(StaticSiteGeneratorCli) private static final Logger logger = LogManager.getLogger(StaticSiteGeneratorCli)
static class LogLevel { private static class LogLevel {
@CommandLine.Option(names = ['--info']) boolean info
@CommandLine.Option(names = ['--debug']) boolean debug @CommandLine.Option(names = ['--info'], description = 'Log at INFO level.')
@CommandLine.Option(names = ['--trace']) boolean trace boolean info
@CommandLine.Option(names = ['--debug'], description = 'Log at DEBUG level.')
boolean debug
@CommandLine.Option(names = ['--trace'], description = 'Log at TRACE level.')
boolean trace
} }
static void main(String[] args) { static void main(String[] args) {
System.exit(new CommandLine(StaticSiteGeneratorCli).execute(args)) System.exit(new CommandLine(StaticSiteGeneratorCli).execute(args))
} }
@CommandLine.ArgGroup(exclusive = true) @CommandLine.ArgGroup(exclusive = true, heading = 'Log Level')
private LogLevel logLevel private LogLevel logLevel
@Override @Override
Integer call() throws Exception { Integer call() throws Exception {
def context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false) // Setup Loggers
def context = (LoggerContext) LogManager.getContext(false)
def configuration = context.getConfiguration() def configuration = context.getConfiguration()
def rootLoggerConfig = configuration.getRootLogger() def rootLoggerConfig = configuration.getRootLogger()
@ -64,6 +71,7 @@ class StaticSiteGeneratorCli implements Callable<Integer> {
context.updateLoggers() context.updateLoggers()
// Configure
def markdownText = new TextType(['.md'], new MarkdownTextRenderer(), new MarkdownFrontMatterGetter()) def markdownText = new TextType(['.md'], new MarkdownTextRenderer(), new MarkdownFrontMatterGetter())
def gspTemplate = new TemplateType(['.gsp'], new GspTemplateRenderer()) def gspTemplate = new TemplateType(['.gsp'], new GspTemplateRenderer())
def gspPart = new PartType(['.gsp'], new GspPartRenderer()) def gspPart = new PartType(['.gsp'], new GspPartRenderer())
@ -83,6 +91,7 @@ class StaticSiteGeneratorCli implements Callable<Integer> {
def globals = [:] def globals = [:]
// Run build script, if applicable
if (new File('build.groovy').exists()) { if (new File('build.groovy').exists()) {
logger.info('found buildScript: build.groovy') logger.info('found buildScript: build.groovy')
def buildScriptRunner = new GroovyBuildScriptRunner() def buildScriptRunner = new GroovyBuildScriptRunner()
@ -91,8 +100,11 @@ class StaticSiteGeneratorCli implements Callable<Integer> {
logger.debug('after running buildScript, globals: {}', globals) logger.debug('after running buildScript, globals: {}', globals)
} }
// Generate
def ssg = new SimpleStaticSiteGenerator(config) def ssg = new SimpleStaticSiteGenerator(config)
ssg.generate(new File('build'), globals) ssg.generate(new File('build'), globals)
// Exit
return 0 return 0
} }