Skip to content

Commit 39edfe8

Browse files
committed
Reorder args in option method, rem auto-naming
1 parent 7f4c2af commit 39edfe8

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

src/main/kotlin/ArgParser.kt

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ class ArgParser(args: Array<out String>,
214214
* @param handler a function that computes the value of this option from an [OptionInvocation]
215215
*/
216216
fun <T> option(
217-
// TODO: fix ordering: help goes first
218217
// TODO: add optionalArg: Boolean
219218
vararg names: String,
220-
errorName: String,
221219
help: String,
220+
// TODO: make errorName nullable, and choose name from option names if null
221+
errorName: String,
222222
argNames: List<String> = emptyList(),
223223
isRepeating: Boolean = false,
224224
handler: OptionInvocation<T>.() -> T
@@ -234,31 +234,6 @@ class ArgParser(args: Array<out String>,
234234
return delegate
235235
}
236236

237-
/**
238-
* Creates a DelegateProvider for an option
239-
* @param errorName name to use when talking about this option in error messages
240-
* @param help the help text for this option
241-
* @param argNames names of this option's arguments
242-
* @param isRepeating whether or not it make sense to repeat this option -- usually used for options where
243-
* specifying the option more than once yields a value than cannot be expressed by specifying the option only once
244-
* @param handler a function that computes the value of this option from an [OptionInvocation]
245-
*/
246-
fun <T> option(
247-
// TODO: fix ordering: help goes first
248-
// TODO: add optionalArg: Boolean
249-
errorName: String,
250-
help: String,
251-
argNames: List<String> = emptyList(),
252-
isRepeating: Boolean = false,
253-
handler: OptionInvocation<T>.() -> T
254-
) = DelegateProvider { name ->
255-
option(identifierToOptionName(name),
256-
errorName = errorName,
257-
help = help,
258-
argNames = argNames,
259-
isRepeating = isRepeating,
260-
handler = handler) }
261-
262237
/**
263238
* Creates a Delegate for a single positional argument which returns the argument's value.
264239
*/
@@ -806,7 +781,6 @@ private const val ARG_INITIAL_CHAR_CLASS = "[A-Z]"
806781
private const val ARG_CHAR_CLASS = "[A-Z0-9]"
807782
private val ARG_NAME_RE = Regex("^$ARG_INITIAL_CHAR_CLASS+([-_]$ARG_CHAR_CLASS+)*$")
808783

809-
810784
fun <T> ArgParser.DelegateProvider<T>.default(newDefault: T): ArgParser.DelegateProvider<T> {
811785
return ArgParser.DelegateProvider(ctor = ctor, defaultHolder = Holder(newDefault))
812786
}

src/test/kotlin/ArgParserTest.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,20 @@
1616
// You should have received a copy of the GNU Lesser General Public License
1717
// along with this library; if not, see http://www.gnu.org/licenses/
1818

19-
package com.xenomachina.argparser
20-
19+
package com.xenomachina.argparser.tests
20+
21+
import com.xenomachina.argparser.ArgParser
22+
import com.xenomachina.argparser.DefaultHelpFormatter
23+
import com.xenomachina.argparser.HelpFormatter
24+
import com.xenomachina.argparser.InvalidArgumentException
25+
import com.xenomachina.argparser.MissingRequiredPositionalArgumentException
26+
import com.xenomachina.argparser.MissingValueException
27+
import com.xenomachina.argparser.OptionMissingRequiredArgumentException
28+
import com.xenomachina.argparser.ShowHelpException
29+
import com.xenomachina.argparser.UnexpectedOptionArgumentException
30+
import com.xenomachina.argparser.UnexpectedPositionalArgumentException
31+
import com.xenomachina.argparser.UnrecognizedOptionException
32+
import com.xenomachina.argparser.default
2133
import com.xenomachina.common.orElse
2234
import io.kotlintest.matchers.Matcher
2335
import io.kotlintest.matchers.Result
@@ -1241,6 +1253,7 @@ class PositionalListDefaultTest : Test({
12411253
class AutoNamedLongOptionWithMultipleArgsTest : Test({
12421254
class Args(parser: ArgParser) {
12431255
val xyz by parser.option<MutableList<String>>(
1256+
"--xyz",
12441257
errorName = "XYZ",
12451258
argNames = listOf("COLOR", "SIZE", "FLAVOR"),
12461259
help = TEST_HELP) {

0 commit comments

Comments
 (0)