Skip to content

Commit

Permalink
cli: data path option
Browse files Browse the repository at this point in the history
  • Loading branch information
Peva Blanchard committed Jan 26, 2024
1 parent d74dc4e commit d6e1c3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions cli/src/main/kotlin/ch/kleis/lcaac/cli/cmd/AssessCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import ch.kleis.lcaac.grammar.LoaderOption
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.help
import com.github.ajalt.clikt.parameters.options.associate
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.help
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.file
import java.io.File

Expand All @@ -27,7 +24,11 @@ class AssessCommand : CliktCommand(name = "assess", help = "Returns the unitary
Example: lcaac assess <process name> -l model="ABC" -l geo="FR".
""".trimIndent())
.associate()
val path: File by option("-p", "--path").file(canBeFile = false).default(File(".")).help("Path to root folder.")
private val getPath = option("-p", "--path").file(canBeFile = false).default(File(".")).help("Path to root folder.")
val path: File by getPath
val dataSourcePath: File by option("--data-path").file(canBeFile = false)
.defaultLazy { getPath.value }
.help("Path to data folder. Default to root folder.")
val file: File? by option("-f", "--file").file(canBeDir = false)
.help("""
CSV file with parameter values.
Expand All @@ -44,7 +45,7 @@ class AssessCommand : CliktCommand(name = "assess", help = "Returns the unitary
override fun run() {
val files = lcaFiles(path)
val symbolTable = Loader(BasicOperations).load(files, listOf(LoaderOption.WITH_PRELUDE))
val processor = CsvProcessor(path, symbolTable)
val processor = CsvProcessor(dataSourcePath, symbolTable)
val iterator = loadRequests()
val writer = CsvResultWriter()
var first = true
Expand Down
13 changes: 7 additions & 6 deletions cli/src/main/kotlin/ch/kleis/lcaac/cli/cmd/TestCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import ch.kleis.lcaac.grammar.LoaderOption
import ch.kleis.lcaac.grammar.parser.LcaLangParser
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.ProgramResult
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.help
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.file
import java.io.File

private const val greenTick = "\u2705"
private const val redCross = "\u274C"

class TestCommand : CliktCommand(name = "test", help = "Run specified tests") {
val path: File by option("-p", "--path").file(canBeFile = false).default(File(".")).help("Path to root folder.")
private val getPath = option("-p", "--path").file(canBeFile = false).default(File(".")).help("Path to root folder.")
val path: File by getPath
val dataSourcePath: File by option("--data-path").file(canBeFile = false)
.defaultLazy { getPath.value }
.help("Path to data folder. Default to root folder.")
val file: File? by option("-f", "--file").file(canBeDir = false)
.help("""
CSV file with parameter values.
Expand All @@ -41,7 +42,7 @@ class TestCommand : CliktCommand(name = "test", help = "Run specified tests") {
.map { mapper.test(it) }
val runner = BasicTestRunner<LcaLangParser.TestDefinitionContext>(
symbolTable,
CsvSourceOperations(path, ops))
CsvSourceOperations(dataSourcePath, ops))
val results = cases.map { runner.run(it) }

results.forEach { result ->
Expand Down

0 comments on commit d6e1c3c

Please sign in to comment.