Skip to content

Commit

Permalink
WIP: Add first CLI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Dec 13, 2023
1 parent b5f78f6 commit 4a8eb7a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
22 changes: 22 additions & 0 deletions htmlSanityCheck-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id 'application'
}

dependencies {
implementation 'info.picocli:picocli:4.7.5'
annotationProcessor 'info.picocli:picocli-codegen:4.7.5'

implementation "org.slf4j:slf4j-api:2.0.7"
implementation "org.slf4j:slf4j-simple:2.0.7"
implementation "org.codehaus.groovy:groovy-all:3.0.17"

implementation project(":htmlSanityCheck-core")
}

compileGroovy {
options.compilerArgs += ["-Aproject=${project.group}/${project.name}"]
}

application {
mainClass = 'org.aim42.htmlsanitycheck.cli.Main'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.aim42.htmlsanitycheck.cli

import org.aim42.htmlsanitycheck.AllChecksRunner
import org.aim42.htmlsanitycheck.Configuration
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Option

// see end-of-file for license information

@Command(name = "hsc", mixinStandardHelpOptions = true, version = "hsc 2.0.0",
description = "Check HTML files for Sanity")
class Main implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(Main.class)

// @Option(names = ["-h", "--help"], usageHelp = true, description = "Display help message")
// void help () {
// logger.info("""SYNOPSIS: htmlSanityCheck
// "-s sourceDir
// "[ -f sourceFile ]+
// "-r resultsDir""")
// }

@Option(names = ["-s", "--sourceDir"], description = "Source Directory")
String sourceDirectoryName

@Option(names = ["-f", "--sourceFile"], description = "Source Directory", arity = "*")
String[] sourceFileNames

@Option(names = ["-r", "--resultsDir"], description = "Results Directory")
String resultsDirectoryName = "/tmp/results"

static void main(String[] args) {
Main app = new Main()
CommandLine cmd = new CommandLine(app)
cmd.execute(args)
}

void run() {
var configuration = new Configuration()

var resultsDirectory = new File(resultsDirectoryName)

configuration.addConfigurationItem(Configuration.ITEM_NAME_sourceDir, new File(sourceDirectoryName))
configuration.addConfigurationItem(Configuration.ITEM_NAME_sourceDocuments,
sourceFileNames.collect {filename ->
return new File(filename)
}
)
configuration.addConfigurationItem((Configuration.ITEM_NAME_checkingResultsDir), resultsDirectory)

if (configuration.isValid()) {
// create output directory for checking results
resultsDirectory.mkdirs()

// create an AllChecksRunner...
var allChecksRunner = new AllChecksRunner(configuration)

// ... and perform the actual checks
var allChecks = allChecksRunner.performAllChecks()

// check for findings and fail build if requested
var nrOfFindingsOnAllPages = allChecks.nrOfFindingsOnAllPages()
logger.debug("Found ${nrOfFindingsOnAllPages} error(s) on all checked pages")
}
}
}

/*========================================================================
Copyright Gerd Aschemann and aim42 contributors
Licensed under the Apache License, Version 2.0 (the "License")
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an
"AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
========================================================================*/
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ gradleEnterprise {
rootProject.name = 'org.aim42.htmlSanityCheck'

include 'htmlSanityCheck-core',
'htmlSanityCheck-gradle-plugin'
'htmlSanityCheck-gradle-plugin',
'htmlSanityCheck-cli'

0 comments on commit 4a8eb7a

Please sign in to comment.