diff --git a/htmlSanityCheck-cli/src/main/groovy/org/aim42/htmlsanitycheck/cli/Main.groovy b/htmlSanityCheck-cli/src/main/groovy/org/aim42/htmlsanitycheck/cli/Main.groovy index 2f5d0c6b..354375fe 100644 --- a/htmlSanityCheck-cli/src/main/groovy/org/aim42/htmlsanitycheck/cli/Main.groovy +++ b/htmlSanityCheck-cli/src/main/groovy/org/aim42/htmlsanitycheck/cli/Main.groovy @@ -5,9 +5,14 @@ import org.aim42.htmlsanitycheck.Configuration import org.slf4j.Logger import org.slf4j.LoggerFactory import picocli.CommandLine +import picocli.CommandLine.Parameters import picocli.CommandLine.Command import picocli.CommandLine.Option +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths + // see end-of-file for license information @Command(name = "hsc", mixinStandardHelpOptions = true, version = "hsc 2.0.0", @@ -23,30 +28,39 @@ class Main implements Runnable { // "-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" + @Parameters(arity = "1..*", description = "at least one File") + File[] files + static void main(String[] args) { Main app = new Main() CommandLine cmd = new CommandLine(app) cmd.execute(args) } + private List findFiles(File directory) throws IOException { + List files = new ArrayList<>() + Files.walk(Paths.get(directory.getPath())) + .filter(Files::isRegularFile) + .filter(path -> path.getFileName().endsWith(".html")) + .forEach(files::add) + return files + } + 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) + files.collect { file -> + if (file.isDirectory()) { + return findFiles(file) + } else { + return new File(file) + } } ) configuration.addConfigurationItem((Configuration.ITEM_NAME_checkingResultsDir), resultsDirectory) diff --git a/htmlSanityCheck-core/src/main/groovy/org/aim42/htmlsanitycheck/Configuration.groovy b/htmlSanityCheck-core/src/main/groovy/org/aim42/htmlsanitycheck/Configuration.groovy index 98a5bbb0..8f739942 100644 --- a/htmlSanityCheck-core/src/main/groovy/org/aim42/htmlsanitycheck/Configuration.groovy +++ b/htmlSanityCheck-core/src/main/groovy/org/aim42/htmlsanitycheck/Configuration.groovy @@ -228,13 +228,13 @@ class Configuration { Set srcDocs = getConfigItemByName(Configuration.ITEM_NAME_sourceDocuments) // cannot check if source director is null (= unspecified) - if ((srcDir == null)) { - throw new MisconfigurationException("source directory must not be null") - } - - if ((!srcDir.exists())) { - throw new MisconfigurationException("given sourceDir $srcDir does not exist.") - } +// if ((srcDir == null)) { +// throw new MisconfigurationException("source directory must not be null") +// } +// +// if ((!srcDir.exists())) { +// throw new MisconfigurationException("given sourceDir $srcDir does not exist.") +// } // cannot check if both input params are null if (srcDocs == null) {