<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Hi,<br>
<br>
I also have a similar library for that purpose:<br>
<br>
<a class="moz-txt-link-freetext" href="https://github.com/AmirAavani/my-units/blob/master/General-Purpose-Units/ParameterManagerUnit.pp">https://github.com/AmirAavani/my-units/blob/master/General-Purpose-Units/ParameterManagerUnit.pp</a><br>
<br>
This library expects "<span class="pl-c">ValidArguments.inc"</span>
file whose content is like the following:<br>
<br>
ValidArgumentsInfo : array of AnsiString =
('--InputFile:AnsiString', '--Debug:Boolean');<br>
ValidArgumentsValues : array of AnsiString = ('', 'True');<br>
<br>
The second array, ValidArgumentsValue (which should be renamed to
DefaultValues) set the default values, if none provided.<br>
<br>
Amir<br>
<br>
<div class="moz-cite-prefix">On 11/20/20 2:38 AM, Benito van der
Zander via fpc-pascal wrote:<br>
</div>
<blockquote type="cite"
cite="mid:fbf20ba0-2fa6-ffe3-4e43-37efa14d0fbc@benibela.de">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div id="smartTemplate4-template">Hi,</div>
<div><br>
</div>
<div>I also made such a thing:</div>
<div><br>
</div>
<div>var optionsreader: TCommandLineReader;<br>
begin<br>
optionsreader := TCommandLineReader.create;<br>
<br>
optionsreader.declareFile('file', 'The file to be processed');<br>
optionsreader.addAbbreviation('f');<br>
<br>
optionsreader.declareFlag('help', '');<br>
optionsreader.addAbbreviation('h');<br>
<br>
optionsreader.declareFlag('version', 'Print the version of the
application');<br>
optionsreader.addAbbreviation('v');<br>
</div>
<div> <br>
</div>
<div> if optionsreader.existsProperty('help') then <br>
</div>
<div> writeln(optionsreader.availableOptions);<br>
<br>
end.<br>
<br>
</div>
<div><br>
</div>
<div>Output:</div>
<div><br>
</div>
<div>--file=<file> or -f The file to be processed<br>
--help or -h <br>
--version or -v Print the version of the application<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>You can download it at <a class="moz-txt-link-freetext"
href="http://www.benibela.de/sources_en.html#rcmdline"
moz-do-not-send="true">http://www.benibela.de/sources_en.html#rcmdline</a><br>
</div>
<div><br>
</div>
<div>Benito</div>
<div><br>
</div>
<div class="moz-cite-prefix">On 20.11.20 01:33, Graeme Geldenhuys
via fpc-pascal wrote:<br>
</div>
<blockquote type="cite"
cite="mid:b6d4f0dd-80bb-4bea-a63e-53649632d368@geldenhuys.co.uk">
<pre class="moz-quote-pre" wrap="">Hi,
I'm working on a automated help output writer(s) for console apps.
Thus no more tedious and ugly output when you do: myapp -h
My aims:
* I write a lot of console apps, so this would be very useful to me.
* Ability to swap out the help formatter. It's interface based, so
custom implementations can easily be created.
* Auto align help options and descriptions - the most annoying thing to
do manually. ;-)
* Ability to define console width in which to format and wrap the help
output, but has a default value.
* The idea is loosely base on the Java version found in Apache Commons.
When it's done I'll obviously shared it as open source somewhere.
With that said, below is how I currently use it. It uses the Builder design
pattern so gives it the Chain Invocations syntax. I know it's not something
often seen in Pascal programs, but it makes it very easy to read and easy
to use/type, especially with code completion editors like Lazarus IDE.
For those console programmers out there... Is there anything in console help
output that you like or wish you had. That way I could possibly add it and
make this even more useful to a wider audience.
I'm still working on AppName, Version and Usage output.
Example code:
==========================
var
optionlist: TOptions;
helpFormatter: IHelpFormatter;
header: string;
footer: string;
begin
optionlist := TOptions.Create;
optionlist.add(TOption.Builder
.isRequired
.withDescription('The file to be processed')
.hasArg
.withArgName('file')
.withLongOpt('file')
.build('f')); // build() always takes the mandatory short option.
optionlist.add(TOption.Builder
.withLongOpt('help')
.withArgName('test') // this is ignored because .hasArg was not specified
.build('h'));
optionlist.add(TOption.Builder
.withDescription('Print the version of the application')
.withLongOpt('version')
.build('v'));
header := 'Do something useful with an input file' + LineEnding;
footer := LineEnding + 'Please report issues at <a class="moz-txt-link-freetext" href="http://example.com/issues" moz-do-not-send="true">http://example.com/issues</a>';
helpFormatter := TBasicHelpFormatter.Create();
// sample outputs with increasing verbosity
writeln('=========================== (1)');
helpFormatter.printHelp(optionlist);
writeln('=========================== (2)');
helpFormatter.printHelp('DocView v1.0', optionlist);
writeln('=========================== (3)');
helpFormatter.printHelp('DocView v1.0', header, optionlist, footer);
writeln('========== the end =================');
optionlist.Free;
end;
==========================
And here is the example output for the 3 options so far:
=========================== (1)
* -f,--file <FILE> The file to be processed
-h,--help
-v,--version Print the version of the application
* indicates required parameters
=========================== (2)
DocView v1.0
* -f,--file <FILE> The file to be processed
-h,--help
-v,--version Print the version of the application
* indicates required parameters
=========================== (3)
DocView v1.0
Do something useful with an input file
* -f,--file <FILE> The file to be processed
-h,--help
-v,--version Print the version of the application
* indicates required parameters
Please report issues at <a class="moz-txt-link-freetext" href="http://example.com/issues" moz-do-not-send="true">http://example.com/issues</a>
========== the end =================
Regards,
Graeme
</pre>
</blockquote>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-pascal maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
</pre>
</blockquote>
<br>
</body>
</html>