Jump to content
Lars Fosdal

Generic Command Line Parser for Delphi 10.3.x

Recommended Posts

I have my own parsing solution, works exactly as I need it to, but it's not as robust as I would like it to be. I will try this one as soon as I have some time!

Share this post


Link to post

Yet another one. 😉

 

I guess sooner or later everybody ends up writing his own, because the built in one is/was not up to par and none of the publicly available ones was popular enough. (When I wrote mine in 2006 I searched for an existing solution that fit my needs and found none.)

 

Here is mine:

https://osdn.net/projects/dzlib-tools/scm/svn/blobs/head/dzlib/trunk/src/u_dzCmdLineParser.pas

 

It allows to register options with and without parameters as well as parameters and can generate help for them. The latter was the feature I was missing with any existing solutions I found.

  • Like 1

Share this post


Link to post

Mine can also quite easily be extended with a short / long description per parameter. 

Share this post


Link to post
29 minutes ago, Микола Петрівський said:

I was expecting to see at least built in support for "--help" and "--version". As it is now, it is not much different to FindCmdLineSwitch.

Except for supporting multiple parameters per option, parameters with spaces, default values, as well as the implicit conversion of ints, floats and enumerated types? 

 

Help would require declaring each command-line option, and help could include short text, long text, as well as examples.

I had to stop somewhere, and since my apps mostly are services or GUI apps, documenting the command line was low on the priority list.

 

As for Version, I suppose there would be as many requirements for what to display (file version, product version, file name, product name, copyright, libs, attributions, etc,) as there are users of the code.
Also - how would you handle those for a GUI app?
 

Other extensions could be to say that an option was mandatory, and if it should be a secret parameter that should be included in the help or not.

It would be trivial to create a specific TFileNameOption that checked that a filename only contained valid characters.

How about a TDateTimeOption?  Cross-option validation?

 

All is possible, and you have the source code and permission to change and build on it.

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×