Freepascal CLI library

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Freepascal CLI library

Darius Blaszyk
I'm working on a CLI application that allows the user to do some configuration. During the process the user is presented with different questions that need to be answered, before the configuration is written to file. For convenience, the user is presented with default options as well. Something like this:

----------
Log files can be written to monitor the performance and debug the application
> Please select whether you would like to write logs to file (y/n) [y]:
----------

Is there a library available that can handle this kind of input from the command line? Though not difficult to write something from scratch (I already started on it), I feel like this has to be available already. Anyone has a tip for me?

TIA!

Rgds, Darius
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal CLI library

wkitty42
On 01/13/2018 04:53 PM, Darius Blaszyk wrote:
> Is there a library available that can handle this kind of input from the
> command line? Though not difficult to write something from scratch (I already
> started on it), I feel like this has to be available already. Anyone has a
> tip for me?

not specific to CLI apps but are you, perhaps, thinking of CheckOptions and
HasOption?

i have a CLI app that is basically a CustApp... CheckOptions allows to check
command line options for short and long variations...

   eg: -h or --help

then options may or may not have parameters... if they have a parameter, they
must always have a parameter...

so basically, there's tMyApplication.DoRun... inside there, i check for command
line options via CheckOptions like the following snippet... it checks for
options such as

   appname -?
   appname -h
   appname --help

the above are all for displaying command line help...

   appname -v
   appname --version

these two display the program version information...

   appname --diag

this is the only option for diagnostic information...

   appname -i <filemask>
   appname --input <filemask>

these two are for input filemask... you probably don't want to worry about the
AppName part... i had to do that for something special in this program... i thin
kto try to have the log file default to the application name unless otherwise
specified with another command line option... i've trimmed things in this quick
snippet...


// TMyApplication
procedure TMyApplication.DoRun;
var
   ErrorMsg: String;
   foo: string;
begin
   // quick check parameters
   ErrorMsg:=CheckOptions('?hvi:','help version diag input:');
   if ErrorMsg<>'' then begin
     writeln('Parameter Error: ',ErrorMsg);
     Terminate;
     Exit;
   end;

//  AppName :=
StringReplace(ExtractFileName(ExeName),ExtractFileExt(ExeName),'',[]);
   foo := paramstr(0);
   AppName := StringReplace(ExtractFileName(foo),ExtractFileExt(foo),'',[]);
   // parse parameters
   if HasOption('?') or HasOption('h','help') then begin
     WriteHelp;
     Terminate;
     Exit;
   end;
   if HasOption('v','version') then begin
     WriteVersion;
     Terminate;
     Exit;
   end;

   ModeDIAG         := HasOption('diag');              // diagnostic mode, show
config and quit
   if HasOption('i','input') then                      // input files mask
     InFile := GetOptionValue('i','input')
   else
     InFile := '*.txt';
[... blah blah blah ...]



--
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list unless*
        *a signed and pre-paid contract is in effect with us.*
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal CLI library

Darius Blaszyk

> not specific to CLI apps but are you, perhaps, thinking of CheckOptions and HasOption?

No I do not look for commandline handling. Rather a CLI interaction library. Which allows to interact with the application during runtime. Similar to how sphinx-quickstart works for instance.

Rgds Darius
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal CLI library

wkitty42
On 01/13/2018 07:28 PM, Darius Blaszyk wrote:
>
>> not specific to CLI apps but are you, perhaps, thinking of CheckOptions and HasOption?
>
> No I do not look for commandline handling. Rather a CLI interaction library.
> Which allows to interact with the application during runtime. Similar to how
> sphinx-quickstart works for instance.

oh, sorry... i misunderstood... i'm not aware of anything like that, really... i
think most folks have a general YesNo routine that returns some value which they
then use to determine which way the code flows... other commands might be
validated by a CheckCMD routine which may then pass valid options off to a
ServiceCMD routine which would then deal with getting the command handled...


--
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list unless*
        *a signed and pre-paid contract is in effect with us.*
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal CLI library

Bart-48
On Sun, Jan 14, 2018 at 6:00 PM,  <[hidden email]> wrote:

> really... i think most folks have a general YesNo routine that returns some
> value which they then use to determine which way the code flows...

I used to have a general Prompt(Question: String; Allowed: TCharSet;
Default: Char; CaseSensitive: Boolean): Char; function for that in the
TP era.
(It used crt unit though. And TCharSet = set of Char)

Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal CLI library

wkitty42
On 01/14/2018 01:15 PM, Bart wrote:
> On Sun, Jan 14, 2018 at 6:00 PM,  <[hidden email]> wrote:
>
>> really... i think most folks have a general YesNo routine that returns some
>> value which they then use to determine which way the code flows...
>
> I used to have a general Prompt(Question: String; Allowed: TCharSet;
> Default: Char; CaseSensitive: Boolean): Char; function for that in the
> TP era.
> (It used crt unit though. And TCharSet = set of Char)


that's another option and it can be altered to work in today's code, too...


--
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list unless*
        *a signed and pre-paid contract is in effect with us.*
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal