Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clikt simplifications #7619

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 38 additions & 54 deletions cli/src/funTest/kotlin/OrtMainFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ class OrtMainFunTest : StringSpec() {
val inputDir = tempdir()

val stdout = OrtMain().test(
listOf(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
)
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
).stdout.lineSequence()
val iterator = stdout.iterator()
while (iterator.hasNext()) {
Expand All @@ -103,13 +101,11 @@ class OrtMainFunTest : StringSpec() {
val inputDir = tempdir()

val stdout = OrtMain().test(
listOf(
"-c", configFile.path,
"-P", "ort.analyzer.disabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
)
"-c", configFile.path,
"-P", "ort.analyzer.disabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
).stdout.lineSequence()
val iterator = stdout.iterator()
while (iterator.hasNext()) {
Expand All @@ -124,14 +120,12 @@ class OrtMainFunTest : StringSpec() {
val inputDir = tempdir()

val stdout = OrtMain().test(
listOf(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle,NPM",
"-P", "ort.analyzer.disabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
)
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle,NPM",
"-P", "ort.analyzer.disabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
).stdout.lineSequence()
val iterator = stdout.iterator()
while (iterator.hasNext()) {
Expand All @@ -147,12 +141,10 @@ class OrtMainFunTest : StringSpec() {
inputDir.resolve("test").writeText("test")

OrtMain().test(
listOf(
"-c", configFile.path,
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
)
"-c", configFile.path,
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
)

val ortResult = outputDir.resolve("analyzer-result.yml").readValue<OrtResult>()
Expand All @@ -168,13 +160,11 @@ class OrtMainFunTest : StringSpec() {
inputDir.resolve("test").writeText("test")

OrtMain().test(
listOf(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle,NPM",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
)
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle,NPM",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
)

val ortResult = outputDir.resolve("analyzer-result.yml").readValue<OrtResult>()
Expand All @@ -188,14 +178,12 @@ class OrtMainFunTest : StringSpec() {
val inputDir = tempdir()

val stdout = OrtMain().test(
listOf(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path,
"-f", "json,yaml,json"
)
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path,
"-f", "json,yaml,json"
).stdout.lineSequence()
val lines = stdout.filter { it.startsWith("Writing analyzer result to ") }

Expand All @@ -210,13 +198,11 @@ class OrtMainFunTest : StringSpec() {
val expectedResult = matchExpectedResult(expectedResultFile, definitionFile)

OrtMain().test(
listOf(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", definitionFile.parentFile.absolutePath,
"-o", outputDir.path
)
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", definitionFile.parentFile.absolutePath,
"-o", outputDir.path
)

val ortResult = outputDir.resolve("analyzer-result.yml").readValue<OrtResult>().withResolvedScopes()
Expand All @@ -228,10 +214,8 @@ class OrtMainFunTest : StringSpec() {
val referenceConfigFile = File("../model/src/main/resources/$REFERENCE_CONFIG_FILENAME").absolutePath

OrtMain().test(
listOf(
"-c", referenceConfigFile,
"config"
)
"-c", referenceConfigFile,
"config"
)

EnvironmentVariableFilter.isAllowed("PASSPORT") shouldBe true
Expand Down
8 changes: 6 additions & 2 deletions cli/src/main/kotlin/OrtMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ private val ORT_LOGO = """
\________/ |____|___/ |____|
""".trimIndent()

private val ORT_LOGO_WIDTH = ORT_LOGO.lines().maxOf { it.length }
// A priority value that is higher than any Clikt built-in value for allocating width.
private const val HIGHEST_PRIORITY_FOR_WIDTH = 100

class OrtMain : CliktCommand(
name = ORT_NAME,
Expand Down Expand Up @@ -171,7 +172,10 @@ class OrtMain : CliktCommand(

private fun getOrtHeader(version: String): Widget =
grid {
column(0) { width = ColumnWidth.Fixed(ORT_LOGO_WIDTH) }
column(0) {
width = ColumnWidth.Custom(width = null, expandWeight = null, priority = HIGHEST_PRIORITY_FOR_WIDTH)
}

column(1) { verticalAlign = VerticalAlign.BOTTOM }
padding { bottom = 1 }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
val expectedOutputFile = getAssetFile("create-analyzer-result-from-pkg-list-expected-output.yml")

HelperMain().test(
listOf(
"create-analyzer-result-from-package-list",
"--package-list-file",
inputFile.absolutePath,
"--ort-file",
outputFile.absolutePath
)
"create-analyzer-result-from-package-list",
"--package-list-file",
inputFile.absolutePath,
"--ort-file",
outputFile.absolutePath
)

outputFile.readValue<OrtResult>().patchAnalyzerResult() shouldBe
Expand Down