Skip to content

Commit 6960fe9

Browse files
committed
Add List<String> overloads to parse and main
1 parent 630ca22 commit 6960fe9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clikt/src/main/kotlin/com/github/ajalt/clikt/core/CliktCommand.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,22 @@ abstract class CliktCommand constructor(
132132
*
133133
* You should use [main] instead unless you want to handle output yourself.
134134
*/
135-
fun parse(argv: Array<String>, context: Context? = null) {
136-
createContext(context)
135+
fun parse(argv: List<String>, parentContext: Context? = null) {
136+
createContext(parentContext)
137137
Parser.parse(argv, this.context)
138138
}
139139

140+
fun parse(argv: Array<String>, parentContext: Context? = null) {
141+
parse(argv.asList(), parentContext)
142+
}
143+
140144
/**
141145
* Parse the command line and print helpful output if any errors occur.
142146
*
143147
* This function calls [parse] and catches and [CliktError]s that are thrown. Other error are allowed to
144148
* pass through.
145149
*/
146-
fun main(argv: Array<String>) {
150+
fun main(argv: List<String>) {
147151
try {
148152
parse(argv)
149153
} catch (e: PrintHelpMessage) {
@@ -164,6 +168,8 @@ abstract class CliktCommand constructor(
164168
}
165169
}
166170

171+
fun main(argv: Array<String>) = main(argv.asList())
172+
167173
/**
168174
* Perform actions after parsing is complete and this command is invoked.
169175
*

clikt/src/main/kotlin/com/github/ajalt/clikt/parsers/Parser.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import com.github.ajalt.clikt.parsers.OptionParser.Invocation
99
import com.github.ajalt.clikt.parsers.OptionParser.ParseResult
1010

1111
internal object Parser {
12-
fun parse(argv: Array<String>, context: Context) {
13-
parse(argv.asList(), context, 0)
12+
fun parse(argv: List<String>, context: Context) {
13+
parse(argv, context, 0)
1414
}
1515

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

0 commit comments

Comments
 (0)