JPL.CmdLineParser

所属分类:Windows编程
开发工具:Delphi
文件大小:15KB
下载次数:0
上传日期:2019-03-20 11:24:39
上 传 者madmax8
说明:  Command-line parser for Delphi and Free Pascal

文件列表:
demos (0, 2019-03-20)
demos\lazarus (0, 2019-03-20)
demos\lazarus\CmdLineParser_Demo.lpi (3556, 2018-04-23)
demos\lazarus\CmdLineParser_Demo.lpr (3091, 2018-04-23)
JPL.CmdLineParser.pas (62490, 2018-04-23)

# JPL.CmdLineParser Command-line parser for Delphi and Free Pascal # Example ```delphi program CmdLineParser_Demo; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} JPL.CmdLineParser; const ENDL = sLineBreak; APP_VERSION_STR = '1.0'; var Cmd: TJPCmdLineParser; procedure RegisterOptions; var Category: string; begin {$IFDEF MSWINDOWS} Cmd.CommandLineParsingMode := cpmCustom; {$ELSE} Cmd.CommandLineParsingMode := cpmDelphi; {$ENDIF} Cmd.UsageFormat := cufWget; Category := 'main'; // Short and long option. Value required. Cmd.RegisterOption('i', 'in-file', cvtRequired, False, False, 'Input file (value required).', 'FILE', Category); // Short and long option. Value optional. Cmd.RegisterOption('o', 'out-file', cvtOptional, False, False, 'Output file (value optional).', 'FILE', Category); // Short and long option. No value. Cmd.RegisterOption('a', 'Option-A', cvtNone, False, False, 'This is an --Option-A description.', '', Category); // Short option. Cmd.RegisterShortOption('b', cvtNone, False, False, 'This is an option -b description.', '', Category); // Long option. Cmd.RegisterLongOption('Option-C', cvtNone, False, False, 'This is an --Option-C description.', '', Category); Category := 'info'; Cmd.RegisterOption('h', 'help', cvtNone, False, False, 'Show help and exit.', '', Category); Cmd.RegisterOption('V', 'version', cvtNone, False, False, 'Show application version and exit.', '', Category); // Hidden option. Cmd.RegisterShortOption('?', cvtNone, False, True, '', '', Category); end; procedure DisplayUsage; var s: string; begin s := 'JPL.CmdLineParser demo application' + ENDL + ENDL + 'Main options: ' + ENDL + Cmd.OptionsUsageStr(' ', 'main', 120, ' ', 30) + ENDL + 'Information: ' + ENDL + Cmd.OptionsUsageStr(' ', 'info', 120, ' ', 30); Writeln(s); end; procedure ProcessOptions; begin if (Cmd.IsOptionExists('h')) or (Cmd.IsOptionExists('?')) then begin DisplayUsage; Exit; end; if Cmd.IsOptionExists('V') then begin Writeln('Version: ', APP_VERSION_STR); Exit; end; if Cmd.IsOptionExists('i') then Writeln('Input file: ', Cmd.GetOptionValue('i')) else Writeln ('Input file: NOT SPECIFIED'); if Cmd.IsOptionExists('o') then Writeln('Output file: ', Cmd.GetOptionValue('o')) else Writeln('Output file: NOT SPECIFIED'); if Cmd.IsOptionExists('a') then Writeln('Option -a: is set') else Writeln('Option -a: NOT SET'); if Cmd.IsShortOptionExists('b') then Writeln('Option -b: is set') else Writeln('Option -b: NOT SET'); if Cmd.IsLongOptionExists('Option-C') then Writeln('Option --Option-C: is set') else Writeln('Option --Option-C: NOT SET'); end; begin Cmd := TJPCmdLineParser.Create; try RegisterOptions; if ParamCount = 0 then begin DisplayUsage; Exit; end; Cmd.Parse; if Cmd.ErrorCount > 0 then begin Writeln('An error occured while parsing command-line options: ', Cmd.ErrorsStr); ExitCode := 1; Exit; end; ProcessOptions; // Do something ... finally Cmd.Free; end; end. ```

近期下载者

相关文件


收藏者