From d05aca1805713333d0e91e630e83c8ec0f824a4a Mon Sep 17 00:00:00 2001 From: kikulacho92 Date: Tue, 7 Oct 2025 10:05:31 +0200 Subject: [PATCH 1/2] added a customizable helpMessage String val to the interface HelpFormatter --- src/main/kotlin/com/xenomachina/argparser/ArgParser.kt | 2 +- .../kotlin/com/xenomachina/argparser/DefaultHelpFormatter.kt | 2 ++ src/main/kotlin/com/xenomachina/argparser/HelpFormatter.kt | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt b/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt index 7375cca..d077737 100644 --- a/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt +++ b/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt @@ -615,7 +615,7 @@ class ArgParser( if (helpFormatter != null) { option("-h", "--help", errorName = "HELP", // This should never be used, but we need to say something - help = "show this help message and exit") { + help = helpFormatter.helpMessage) { throw ShowHelpException(helpFormatter, delegates.toList()) }.default(Unit).registerRoot() } diff --git a/src/main/kotlin/com/xenomachina/argparser/DefaultHelpFormatter.kt b/src/main/kotlin/com/xenomachina/argparser/DefaultHelpFormatter.kt index ea23ef3..bfcae98 100644 --- a/src/main/kotlin/com/xenomachina/argparser/DefaultHelpFormatter.kt +++ b/src/main/kotlin/com/xenomachina/argparser/DefaultHelpFormatter.kt @@ -65,6 +65,8 @@ class DefaultHelpFormatter( val indent = " " val indentWidth = indent.codePointWidth() + override value helpMessage = "show this help message and exit" + override fun format( programName: String?, columns: Int, diff --git a/src/main/kotlin/com/xenomachina/argparser/HelpFormatter.kt b/src/main/kotlin/com/xenomachina/argparser/HelpFormatter.kt index 5b13b1d..6c0f429 100644 --- a/src/main/kotlin/com/xenomachina/argparser/HelpFormatter.kt +++ b/src/main/kotlin/com/xenomachina/argparser/HelpFormatter.kt @@ -22,6 +22,11 @@ package com.xenomachina.argparser * Formats help for an [ArgParser]. */ interface HelpFormatter { + + /** + * The help message added automatically with the options -h, --help + */ + val helpMessage: String /** * Formats a help message. * From 512ffadaa1a1c0090d3c5f6e9bebf453537e51f1 Mon Sep 17 00:00:00 2001 From: kikulacho92 Date: Tue, 7 Oct 2025 10:12:34 +0200 Subject: [PATCH 2/2] I have added a new String immutable property in HelpFormatter to make it more customizable. The version of ArgParser that I forked did not allow to customize the message "show this message and exit" associated to the option -h, --help. This could cause problems, for example, with internationalization and localization issues. In this version, the property HelpFormatter.helpMessage is called in the init block of ArgParser (ArgParser.kt/614): init { if (helpFormatter != null) { option("-h", "--help", errorName = "HELP", // This should never be used, but we need to say something help = helpFormatter.helpMessage) { //now this message is customizable throw ShowHelpException(helpFormatter, delegates.toList()) }.default(Unit).registerRoot() } } making therefore this message customizable. --- src/main/kotlin/com/xenomachina/argparser/ArgParser.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt b/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt index d077737..ee04290 100644 --- a/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt +++ b/src/main/kotlin/com/xenomachina/argparser/ArgParser.kt @@ -615,7 +615,7 @@ class ArgParser( if (helpFormatter != null) { option("-h", "--help", errorName = "HELP", // This should never be used, but we need to say something - help = helpFormatter.helpMessage) { + help = helpFormatter.helpMessage) { //now this message is customizable throw ShowHelpException(helpFormatter, delegates.toList()) }.default(Unit).registerRoot() }