Skip to content

Commit 40202f1

Browse files
committed
Improve epilogue formatting
Also refactor DelegateProviderTest slightly.
1 parent 8e91c69 commit 40202f1

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/main/kotlin/ArgParser.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,10 @@ class DefaultHelpFormatter(
934934
appendSection(sb, usageColumns, columns, "optional", optional)
935935
appendSection(sb, usageColumns, columns, "positional", positional)
936936

937-
if (!epilogue.isNullOrEmpty()) {
937+
if (!epilogue?.trim().isNullOrEmpty()) {
938938
sb.append("\n")
939939
// we just checked that epilogue is non-null
940-
sb.append(epilogue!!.wrapText(columns))
940+
sb.append(epilogue!!.trim().wrapText(columns))
941941
sb.append("\n")
942942
}
943943

src/test/kotlin/ArgParserTest.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,18 @@ class LongOptionsWithMultipleArgsTest : Test({
361361
})
362362

363363
class DelegateProviderTest : Test({
364-
fun ArgParser.putting(help: String): ArgParser.DelegateProvider<Map<String, String>> =
365-
ArgParser.DelegateProvider { identifier ->
366-
option<MutableMap<String, String>>(identifierToOptionName(identifier),
367-
argNames = listOf("KEY", "VALUE"),
368-
help = help) {
369-
value.orElse { mutableMapOf<String, String>() }.apply { put(arguments.first(), arguments.last()) }
370-
}
364+
fun ArgParser.putting(vararg names: String, help: String) =
365+
option<MutableMap<String, String>>(*names,
366+
argNames = listOf("KEY", "VALUE"),
367+
help = help) {
368+
value.orElse { mutableMapOf<String, String>() }.apply {
369+
put(arguments.first(), arguments.last()) }
371370
}
371+
372+
fun ArgParser.putting(help: String) =
373+
ArgParser.DelegateProvider { identifier ->
374+
putting(identifierToOptionName(identifier), help = help) }
375+
372376
class Args(parser: ArgParser) {
373377
val dict by parser.putting(TEST_HELP)
374378
}
@@ -1018,12 +1022,11 @@ positional arguments:
10181022
DEST destination file
10191023
10201024
1021-
1022-
This is the epilogue. Lorem ipsum dolor sit amet, consectetur
1023-
adipiscing elit. Donec vel tortor nunc. Sed eu massa sed
1024-
turpis auctor faucibus. Donec vel pellentesque tortor. Ut
1025-
ultrices tempus lectus fermentum vestibulum. Phasellus.
1026-
1025+
This is the epilogue. Lorem ipsum dolor sit amet,
1026+
consectetur adipiscing elit. Donec vel tortor nunc. Sed eu
1027+
massa sed turpis auctor faucibus. Donec vel pellentesque
1028+
tortor. Ut ultrices tempus lectus fermentum vestibulum.
1029+
Phasellus.
10271030
""".trimStart()
10281031
}
10291032
})

0 commit comments

Comments
 (0)