@@ -35,9 +35,11 @@ import kotlin.reflect.KProperty
3535 * @param helpFormatter if non-null, creates `--help` and `-h` options that trigger a [ShowHelpException] which will use
3636 * the supplied [HelpFormatter] to generate a help message.
3737 */
38- class ArgParser (args : Array <out String >,
39- mode : Mode = Mode .GNU ,
40- helpFormatter : HelpFormatter ? = DefaultHelpFormatter ()) {
38+ class ArgParser (
39+ args : Array <out String >,
40+ mode : Mode = Mode .GNU ,
41+ helpFormatter : HelpFormatter ? = DefaultHelpFormatter ()
42+ ) {
4143
4244 enum class Mode {
4345 /* * For GNU-style option parsing, where options may appear after positional arguments. */
@@ -79,10 +81,10 @@ class ArgParser(args: Array<out String>,
7981 * Creates a Delegate for a single-argument option that stores and returns the option's (transformed) argument.
8082 */
8183 fun <T > storing (
82- vararg names : String ,
83- help : String ,
84- argName : String? = null,
85- transform : String .() -> T
84+ vararg names : String ,
85+ help : String ,
86+ argName : String? = null,
87+ transform : String .() -> T
8688 ): Delegate <T > {
8789 val nonNullArgName = argName ? : optionNameToArgName(selectRepresentativeOptionName(names))
8890 return option(
@@ -96,9 +98,9 @@ class ArgParser(args: Array<out String>,
9698 * Creates a DelegateProvider for a single-argument option that stores and returns the option's (transformed) argument.
9799 */
98100 fun <T > storing (
99- help : String ,
100- argName : String? = null,
101- transform : String .() -> T
101+ help : String ,
102+ argName : String? = null,
103+ transform : String .() -> T
102104 ) = DelegateProvider { identifier -> storing(identifierToOptionName(identifier), help = help, argName = argName, transform = transform) }
103105
104106 /* *
@@ -119,11 +121,11 @@ class ArgParser(args: Array<out String>,
119121 * MutableCollection each time the option appears in args, and returns said MutableCollection.
120122 */
121123 fun <E , T : MutableCollection <E >> adding (
122- vararg names : String ,
123- help : String ,
124- argName : String? = null,
125- initialValue : T ,
126- transform : String .() -> E
124+ vararg names : String ,
125+ help : String ,
126+ argName : String? = null,
127+ initialValue : T ,
128+ transform : String .() -> E
127129 ): Delegate <T > {
128130 val nonNullArgName = argName ? : optionNameToArgName(selectRepresentativeOptionName(names))
129131 return option<T >(
@@ -142,10 +144,10 @@ class ArgParser(args: Array<out String>,
142144 * MutableCollection each time the option appears in args, and returns said MutableCollection.
143145 */
144146 fun <E , T : MutableCollection <E >> adding (
145- help : String ,
146- argName : String? = null,
147- initialValue : T ,
148- transform : String .() -> E
147+ help : String ,
148+ argName : String? = null,
149+ initialValue : T ,
150+ transform : String .() -> E
149151 ) = DelegateProvider { identifier ->
150152 adding(identifierToOptionName(identifier), help = help, argName = argName, initialValue = initialValue, transform = transform) }
151153
@@ -154,20 +156,20 @@ class ArgParser(args: Array<out String>,
154156 * MutableList each time the option appears in args, and returns said MutableCollection.
155157 */
156158 fun <T > adding (
157- vararg names : String ,
158- help : String ,
159- argName : String? = null,
160- transform : String .() -> T
159+ vararg names : String ,
160+ help : String ,
161+ argName : String? = null,
162+ transform : String .() -> T
161163 ) = adding(* names, help = help, argName = argName, initialValue = mutableListOf (), transform = transform)
162164
163165 /* *
164166 * Creates a DelegateProvider for a single-argument option that adds the option's (transformed) argument to a
165167 * MutableList each time the option appears in args, and returns said MutableCollection.
166168 */
167169 fun <T > adding (
168- help : String ,
169- argName : String? = null,
170- transform : String .() -> T
170+ help : String ,
171+ argName : String? = null,
172+ transform : String .() -> T
171173 ) = DelegateProvider { identifier ->
172174 adding(identifierToOptionName(identifier), help = help, argName = argName, transform = transform) }
173175
@@ -219,13 +221,13 @@ class ArgParser(args: Array<out String>,
219221 * @param handler a function that computes the value of this option from an [OptionInvocation]
220222 */
221223 fun <T > option (
222- // TODO: add optionalArg: Boolean
223- vararg names : String ,
224- help : String ,
225- errorName : String? = null,
226- argNames : List <String > = emptyList(),
227- isRepeating : Boolean = false,
228- handler : OptionInvocation <T >.() -> T
224+ // TODO: add optionalArg: Boolean
225+ vararg names : String ,
226+ help : String ,
227+ errorName : String? = null,
228+ argNames : List <String > = emptyList(),
229+ isRepeating : Boolean = false,
230+ handler : OptionInvocation <T >.() -> T
229231 ): Delegate <T > {
230232 val delegate = OptionDelegate <T >(
231233 parser = this ,
@@ -253,9 +255,9 @@ class ArgParser(args: Array<out String>,
253255 * Creates a Delegate for a single positional argument which returns the argument's transformed value.
254256 */
255257 fun <T > positional (
256- name : String ,
257- help : String ,
258- transform : String .() -> T
258+ name : String ,
259+ help : String ,
260+ transform : String .() -> T
259261 ): Delegate <T > {
260262 return WrappingDelegate (
261263 positionalList(name, help = help, sizeRange = 1 .. 1 , transform = transform)
@@ -266,36 +268,36 @@ class ArgParser(args: Array<out String>,
266268 * Creates a DelegateProvider for a single positional argument which returns the argument's transformed value.
267269 */
268270 fun <T > positional (
269- help : String ,
270- transform : String .() -> T
271+ help : String ,
272+ transform : String .() -> T
271273 ) = DelegateProvider { identifier -> positional(identifierToArgName(identifier), help = help, transform = transform) }
272274
273275 /* *
274276 * Creates a Delegate for a sequence of positional arguments which returns a List containing the arguments.
275277 */
276278 fun positionalList (
277- name : String ,
278- help : String ,
279- sizeRange : IntRange = 1..Int .MAX_VALUE
279+ name : String ,
280+ help : String ,
281+ sizeRange : IntRange = 1..Int .MAX_VALUE
280282 ) = positionalList(name, help = help, sizeRange = sizeRange) { this }
281283
282284 /* *
283285 * Creates a DelegateProvider for a sequence of positional arguments which returns a List containing the arguments.
284286 */
285287 fun positionalList (
286- help : String ,
287- sizeRange : IntRange = 1..Int .MAX_VALUE
288+ help : String ,
289+ sizeRange : IntRange = 1..Int .MAX_VALUE
288290 ) = DelegateProvider { identifier -> positionalList(identifierToArgName(identifier), help = help, sizeRange = sizeRange) }
289291
290292 /* *
291293 * Creates a Delegate for a sequence of positional arguments which returns a List containing the transformed
292294 * arguments.
293295 */
294296 fun <T > positionalList (
295- name : String ,
296- help : String ,
297- sizeRange : IntRange = 1..Int .MAX_VALUE ,
298- transform : String .() -> T
297+ name : String ,
298+ help : String ,
299+ sizeRange : IntRange = 1..Int .MAX_VALUE ,
300+ transform : String .() -> T
299301 ): Delegate <List <T >> {
300302 sizeRange.run {
301303 if (step != 1 )
@@ -318,9 +320,9 @@ class ArgParser(args: Array<out String>,
318320 * arguments.
319321 */
320322 fun <T > positionalList (
321- help : String ,
322- sizeRange : IntRange = 1..Int .MAX_VALUE ,
323- transform : String .() -> T
323+ help : String ,
324+ sizeRange : IntRange = 1..Int .MAX_VALUE ,
325+ transform : String .() -> T
324326 ) = DelegateProvider { identifier -> positionalList(identifierToArgName(identifier), help, sizeRange, transform) }
325327
326328 abstract class Delegate <out T > internal constructor() {
@@ -381,8 +383,8 @@ class ArgParser(args: Array<out String>,
381383 * specifying a name explicitly.
382384 */
383385 class DelegateProvider <out T >(
384- private val default : (() -> T )? = null ,
385- internal val ctor : (identifier: String ) -> Delegate <T >
386+ private val default : (() -> T )? = null ,
387+ internal val ctor : (identifier: String ) -> Delegate <T >
386388 ) {
387389 operator fun provideDelegate (thisRef : Any? , prop : KProperty <* >): Delegate <T > {
388390 val delegate = ctor(prop.name)
@@ -397,11 +399,12 @@ class ArgParser(args: Array<out String>,
397399 * @property arguments the arguments supplied for this option
398400 */
399401 data class OptionInvocation <T > internal constructor(
400- // Internal constructor so future versions can add properties
401- // without breaking compatibility.
402- val value : Holder <T >? ,
403- val optionName : String ,
404- val arguments : List <String >)
402+ // Internal constructor so future versions can add properties
403+ // without breaking compatibility.
404+ val value : Holder <T >? ,
405+ val optionName : String ,
406+ val arguments : List <String >
407+ )
405408
406409 private val shortOptionDelegates = mutableMapOf<Char , OptionDelegate <* >>()
407410 private val longOptionDelegates = mutableMapOf<String , OptionDelegate <* >>()
0 commit comments