Skip to content

Commit

Permalink
Add List<String> overloads to parse and main
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt committed Apr 15, 2018
1 parent 630ca22 commit 6960fe9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,22 @@ abstract class CliktCommand constructor(
*
* You should use [main] instead unless you want to handle output yourself.
*/
fun parse(argv: Array<String>, context: Context? = null) {
createContext(context)
fun parse(argv: List<String>, parentContext: Context? = null) {
createContext(parentContext)
Parser.parse(argv, this.context)
}

fun parse(argv: Array<String>, parentContext: Context? = null) {
parse(argv.asList(), parentContext)
}

/**
* Parse the command line and print helpful output if any errors occur.
*
* This function calls [parse] and catches and [CliktError]s that are thrown. Other error are allowed to
* pass through.
*/
fun main(argv: Array<String>) {
fun main(argv: List<String>) {
try {
parse(argv)
} catch (e: PrintHelpMessage) {
Expand All @@ -164,6 +168,8 @@ abstract class CliktCommand constructor(
}
}

fun main(argv: Array<String>) = main(argv.asList())

/**
* Perform actions after parsing is complete and this command is invoked.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.github.ajalt.clikt.parsers.OptionParser.Invocation
import com.github.ajalt.clikt.parsers.OptionParser.ParseResult

internal object Parser {
fun parse(argv: Array<String>, context: Context) {
parse(argv.asList(), context, 0)
fun parse(argv: List<String>, context: Context) {
parse(argv, context, 0)
}

private tailrec fun parse(argv: List<String>, context: Context, startingArgI: Int) {
Expand Down

0 comments on commit 6960fe9

Please sign in to comment.