Skip to content

Commit

Permalink
WIP Switch to CLI parameters (instead of options)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Dec 13, 2023
1 parent 4a8eb7a commit 25a147c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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<File> findFiles(File directory) throws IOException {
List<File> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ class Configuration {
Set<String> 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) {
Expand Down

0 comments on commit 25a147c

Please sign in to comment.