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

Allow CliktCommand.test to take a vararg #451

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.github.ajalt.clikt.parsers.shlex
import com.github.ajalt.mordant.rendering.AnsiLevel
import com.github.ajalt.mordant.terminal.Terminal
import com.github.ajalt.mordant.terminal.TerminalRecorder
import kotlin.jvm.JvmName

data class CliktCommandTestResult(
/** Standard output captured from the command */
Expand Down Expand Up @@ -52,6 +53,33 @@ fun CliktCommand.test(
return test(argvArray, stdin, envvars, includeSystemEnvvars, ansiLevel, width, height)
}

/**
* Test this command, returning a result that captures the output and result status code.
*
* Note that only output printed with [echo][CliktCommand.echo] will be captured. Anything printed with [print] or
* [println] is not.
*
* @param argv The command line to send to the command
* @param stdin Content of stdin that will be read by prompt options. Multiple inputs should be separated by `\n`.
* @param envvars A map of environment variable name to value for envvars that can be read by the command
* @param includeSystemEnvvars Set to true to include the environment variables from the system in addition to those
* defined in [envvars]
* @param ansiLevel Defaults to no colored output; set to [AnsiLevel.TRUECOLOR] to include ANSI codes in the output.
* @param width The width of the terminal, used to wrap text
* @param height The height of the terminal
*/
@JvmName("varargTest")
fun CliktCommand.test(
vararg argv: String,
stdin: String = "",
envvars: Map<String, String> = emptyMap(),
includeSystemEnvvars: Boolean = false,
ansiLevel: AnsiLevel = AnsiLevel.NONE,
width: Int = 79,
height: Int = 24,
): CliktCommandTestResult {
return test(argv.asList(), stdin, envvars, includeSystemEnvvars, ansiLevel, width, height)
}

/**
* Test this command, returning a result that captures the output and result status code.
Expand Down