diff --git a/src/main/kotlin/slack/cli/exec/ProcessedExecCli.kt b/src/main/kotlin/slack/cli/exec/ProcessedExecCli.kt index c3817d4..76e5f78 100644 --- a/src/main/kotlin/slack/cli/exec/ProcessedExecCli.kt +++ b/src/main/kotlin/slack/cli/exec/ProcessedExecCli.kt @@ -31,6 +31,7 @@ import kotlin.io.path.deleteRecursively import kotlin.system.exitProcess import okio.buffer import okio.source +import org.jetbrains.annotations.TestOnly import slack.cli.projectDirOption /** @@ -44,17 +45,21 @@ import slack.cli.projectDirOption public class ProcessedExecCli : CliktCommand("Executes a command with Bugsnag tracing and retries as needed.") { - private val projectDir by projectDirOption() - private val verbose by option("--verbose", "-v").flag() - private val bugsnagKey by option("--bugsnag-key", envvar = "PE_BUGSNAG_KEY") - private val configurationFile by + internal val projectDir by projectDirOption() + internal val verbose by option("--verbose", "-v").flag() + internal val bugsnagKey by option("--bugsnag-key", envvar = "PE_BUGSNAG_KEY") + internal val configurationFile by option("--config", envvar = "PE_CONFIGURATION_FILE") .path(mustExist = true, canBeFile = true, canBeDir = false) - private val args by argument().multiple() + @get:TestOnly internal val parseOnly by option("--parse-only").flag(default = false) + + internal val args by argument().multiple() @OptIn(ExperimentalStdlibApi::class, ExperimentalPathApi::class) override fun run() { + if (parseOnly) return + val moshi = ProcessingUtil.newMoshi() val config = configurationFile?.let { diff --git a/src/test/kotlin/slack/cli/exec/ProcessedExecCliTest.kt b/src/test/kotlin/slack/cli/exec/ProcessedExecCliTest.kt new file mode 100644 index 0000000..8800686 --- /dev/null +++ b/src/test/kotlin/slack/cli/exec/ProcessedExecCliTest.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2023 Slack Technologies, LLC + * + * 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 + * + * https://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. + */ +package slack.cli.exec + +import com.google.common.truth.Truth.assertThat +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +class ProcessedExecCliTest { + + @JvmField @Rule val temporaryFolder = TemporaryFolder() + + @Test + fun standardParsing() { + val configFile = temporaryFolder.newFile("config.json") + val args = "./gradlew build -Pvariant=debug" + val parsed = + ProcessedExecCli().apply { + parse( + arrayOf( + "--project-dir", + temporaryFolder.root.absolutePath, + "--bugsnag-key=1234", + "--verbose", + "--parse-only", + "--config", + configFile.absolutePath, + "--", + args + ) + ) + } + assertThat(parsed.projectDir).isEqualTo(temporaryFolder.root.toPath()) + assertThat(parsed.verbose).isTrue() + assertThat(parsed.bugsnagKey).isEqualTo("1234") + assertThat(parsed.configurationFile).isEqualTo(configFile.toPath()) + assertThat(parsed.args).isEqualTo(listOf(args)) + } +}