Skip to content

Commit 39e4cb9

Browse files
committed
Fix a bunch of formatting issues
These are caught by a newer version of ktlint
1 parent 9173de3 commit 39e4cb9

File tree

9 files changed

+106
-97
lines changed

9 files changed

+106
-97
lines changed

src/main/kotlin/com/xenomachina/argparser/ArgParser.kt

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -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<*>>()

src/main/kotlin/com/xenomachina/argparser/DefaultHelpFormatter.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ import com.xenomachina.text.term.wrapText
5959
* @property epilogue Text that should appear at the end of the help.
6060
*/
6161
class DefaultHelpFormatter(
62-
val prologue: String? = null,
63-
val epilogue: String? = null
62+
val prologue: String? = null,
63+
val epilogue: String? = null
6464
) : HelpFormatter {
6565
val indent = " "
6666
val indentWidth = indent.codePointWidth()
6767

6868
override fun format(
69-
programName: String?,
70-
columns: Int,
71-
values: List<HelpFormatter.Value>
69+
programName: String?,
70+
columns: Int,
71+
values: List<HelpFormatter.Value>
7272
): String {
7373
val effectiveColumns = when {
7474
columns < 0 -> throw IllegalArgumentException("columns must be non-negative")
@@ -121,11 +121,11 @@ class DefaultHelpFormatter(
121121
}
122122

123123
private fun appendSection(
124-
sb: StringBuilder,
125-
usageColumns: Int,
126-
columns: Int,
127-
name: String,
128-
values: List<HelpFormatter.Value>
124+
sb: StringBuilder,
125+
usageColumns: Int,
126+
columns: Int,
127+
name: String,
128+
values: List<HelpFormatter.Value>
129129
) {
130130

131131
if (!values.isEmpty()) {

src/main/kotlin/com/xenomachina/argparser/Exceptions.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import java.io.Writer
2525
* `--help` option, for example).
2626
*/
2727
class ShowHelpException internal constructor(
28-
private val helpFormatter: HelpFormatter,
29-
private val delegates: List<ArgParser.Delegate<*>>
28+
private val helpFormatter: HelpFormatter,
29+
private val delegates: List<ArgParser.Delegate<*>>
3030
) : SystemExitException("Help was requested", 0) {
3131
override fun printUserMessage(writer: Writer, programName: String?, columns: Int) {
3232
writer.write(helpFormatter.format(programName, columns, delegates.map { it.toHelpFormatterValue() }))
@@ -61,9 +61,11 @@ open class InvalidArgumentException(message: String) : SystemExitException(messa
6161
* @property argName the name of the missing argument, or null
6262
*/
6363
open class OptionMissingRequiredArgumentException(val optName: String, val argName: String? = null) :
64-
SystemExitException("option '$optName' is missing "
65-
+ (if (argName == null) "a required argument" else "the required argument $argName"),
66-
2)
64+
SystemExitException(
65+
"option '$optName' is missing " + (
66+
if (argName == null) "a required argument"
67+
else "the required argument $argName"),
68+
2)
6769

6870
/**
6971
* Indicates that a required positional argument was not supplied.

src/main/kotlin/com/xenomachina/argparser/HelpFormatter.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ interface HelpFormatter {
4343
* @param help help text provided at Delegate construction time
4444
*/
4545
data class Value(
46-
val usages: List<String>,
47-
val isRequired: Boolean,
48-
val isRepeating: Boolean,
49-
val isPositional: Boolean,
50-
val help: String)
46+
val usages: List<String>,
47+
val isRequired: Boolean,
48+
val isRepeating: Boolean,
49+
val isPositional: Boolean,
50+
val help: String
51+
)
5152
}

src/main/kotlin/com/xenomachina/argparser/OptionDelegate.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ package com.xenomachina.argparser
2121
import com.xenomachina.common.Holder
2222

2323
internal class OptionDelegate<T>(
24-
parser: ArgParser,
25-
errorName: String,
26-
help: String,
27-
val optionNames: List<String>,
28-
val argNames: List<String>,
29-
val isRepeating: Boolean,
30-
val handler: ArgParser.OptionInvocation<T>.() -> T) : ParsingDelegate<T>(parser, errorName, help) {
24+
parser: ArgParser,
25+
errorName: String,
26+
help: String,
27+
val optionNames: List<String>,
28+
val argNames: List<String>,
29+
val isRepeating: Boolean,
30+
val handler: ArgParser.OptionInvocation<T>.() -> T
31+
) : ParsingDelegate<T>(parser, errorName, help) {
3132
init {
3233
for (optionName in optionNames) {
3334
if (!OPTION_NAME_RE.matches(optionName)) {

src/main/kotlin/com/xenomachina/argparser/ParsingDelegate.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ package com.xenomachina.argparser
2121
import com.xenomachina.common.Holder
2222

2323
internal abstract class ParsingDelegate<T>(
24-
override val parser: ArgParser,
25-
override val errorName: String,
26-
override val help: String) : ArgParser.Delegate<T>() {
24+
override val parser: ArgParser,
25+
override val errorName: String,
26+
override val help: String
27+
) : ArgParser.Delegate<T>() {
2728

2829
protected var holder: Holder<T>? = null
2930

src/main/kotlin/com/xenomachina/argparser/PositionalDelegate.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ package com.xenomachina.argparser
2121
import com.xenomachina.common.Holder
2222

2323
internal class PositionalDelegate<T>(
24-
parser: ArgParser,
25-
argName: String,
26-
val sizeRange: IntRange,
27-
help: String,
28-
val transform: String.() -> T) : ParsingDelegate<List<T>>(parser, argName, help) {
24+
parser: ArgParser,
25+
argName: String,
26+
val sizeRange: IntRange,
27+
help: String,
28+
val transform: String.() -> T
29+
) : ParsingDelegate<List<T>>(parser, argName, help) {
2930

3031
init {
3132
if (!ARG_NAME_RE.matches(argName)) {

src/main/kotlin/com/xenomachina/argparser/WrappingDelegate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package com.xenomachina.argparser
2020

2121
internal class WrappingDelegate<U, W>(
22-
private val inner: ArgParser.Delegate<U>,
23-
private val wrap: (U) -> W
22+
private val inner: ArgParser.Delegate<U>,
23+
private val wrap: (U) -> W
2424
) : ArgParser.Delegate<W>() {
2525

2626
override val parser: ArgParser

src/test/kotlin/com/xenomachina/argparser/ArgParserTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import java.io.StringWriter
3232
val TEST_HELP = "test help message"
3333

3434
fun parserOf(
35-
vararg args: String,
36-
mode: ArgParser.Mode = ArgParser.Mode.GNU,
37-
helpFormatter: HelpFormatter? = DefaultHelpFormatter()
35+
vararg args: String,
36+
mode: ArgParser.Mode = ArgParser.Mode.GNU,
37+
helpFormatter: HelpFormatter? = DefaultHelpFormatter()
3838
) = ArgParser(args, mode, helpFormatter)
3939

4040
enum class Color { RED, GREEN, BLUE }

0 commit comments

Comments
 (0)