Project In-Line Help: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Overview=
=Overview=


The best mechanism so far is to maintain a HELP.txt file within the resources of the project, embed it into the root of the JAR artifact and dump it at stdout when needed.
The best mechanism so far to display in-line help is to maintain a help.txt file within the resources of the project, embed it into the root of the JAR artifact and dump it at stdout when needed.


The code that reads the help file is the self-contained class InLineHelp that can be placed in the <tt>util</tt> package of the project:
Place the text help file ("help.txt" or "HELP.txt") in <tt>./src/main/resources</tt> of the project, so it will be automatically bundled by Maven into the final JAR.


<pre>
The code that reads the help file is the self-contained class InLineHelp that can be placed in the <tt>util</tt> package of the project.
</pre>
 
=Implementation=
 
There's a novaordis-utilities version, in case the project already depends on novaordis-utilities:
 
{{External|https://github.com/NovaOrdis/novaordis-utilities/blob/master/src/main/java/io/novaordis/utilities/help/InLineHelp.java}}
 
InLineHelp.java can be used as a starting point for a standalone implementation.
 
==Usage==
 
<syntaxhighlight lang='java'>
try {
 
    System.out.println(InLineHelp.get());
}
catch(UserErrorException e) {
 
    System.err.println(e.getMessage());
}
</syntaxhighlight>
 
=Line Length=
 
103 characters.
 
0123456789##########0123456789##########0123456789## 103 ###0123456789##########0123456789##########123

Latest revision as of 07:46, 23 March 2019

Internal

Overview

The best mechanism so far to display in-line help is to maintain a help.txt file within the resources of the project, embed it into the root of the JAR artifact and dump it at stdout when needed.

Place the text help file ("help.txt" or "HELP.txt") in ./src/main/resources of the project, so it will be automatically bundled by Maven into the final JAR.

The code that reads the help file is the self-contained class InLineHelp that can be placed in the util package of the project.

Implementation

There's a novaordis-utilities version, in case the project already depends on novaordis-utilities:

https://github.com/NovaOrdis/novaordis-utilities/blob/master/src/main/java/io/novaordis/utilities/help/InLineHelp.java

InLineHelp.java can be used as a starting point for a standalone implementation.

Usage

try {

    System.out.println(InLineHelp.get());
}
catch(UserErrorException e) {

    System.err.println(e.getMessage());
}

Line Length

103 characters.

0123456789##########0123456789##########0123456789## 103 ###0123456789##########0123456789##########123