diff --git a/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt b/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt index 06dbb0e..4c929da 100644 --- a/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt +++ b/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt @@ -37,7 +37,8 @@ import kotlin.reflect.KProperty */ class ArgParser(args: Array, mode: Mode = Mode.GNU, - helpFormatter: HelpFormatter? = DefaultHelpFormatter()) { + helpFormatter: HelpFormatter? = DefaultHelpFormatter(), + val skipUnknown: Boolean = false) { enum class Mode { /** For GNU-style option parsing, where options may appear after positional arguments. */ @@ -543,7 +544,11 @@ class ArgParser(args: Array, } val delegate = longOptionDelegates.get(name) if (delegate == null) { - throw UnrecognizedOptionException(name) + if (!skipUnknown) { + throw UnrecognizedOptionException(name) + } else { + return 2 // @todo rewrite to correct count detection + } } else { var consumedArgs = delegate.parseOption(name, firstArg, index + 1, args) if (firstArg != null) { @@ -569,7 +574,11 @@ class ArgParser(args: Array, val delegate = shortOptionDelegates.get(optKey) if (delegate == null) { - throw UnrecognizedOptionException(optName) + if (!skipUnknown) { + throw UnrecognizedOptionException(optName) + } else { + return 2 // @todo rewrite to correct count detection + } } else { val firstArg = if (optIndex >= opts.length) null else opts.substring(optIndex) val consumed = delegate.parseOption(optName, firstArg, index + 1, args)