Simplified command line parameter handling

This commit is contained in:
Andreas Schneider 2015-09-28 10:21:55 +02:00
parent d0633ccb83
commit 2752c839ed
1 changed files with 14 additions and 8 deletions

View File

@ -58,6 +58,12 @@ type
implementation implementation
{Some trickery to have clean command line option checks}
{$MACRO ON}
{$define OPT_COMMANDFILE:='c', 'commandfile'}
{$define OPT_SIMPLE:='s', 'simple'}
{$define OPT_LOGFILE:='f', 'logfile'}
{ TLogFilterApplication } { TLogFilterApplication }
procedure TLogFilterApplication.DoRun; procedure TLogFilterApplication.DoRun;
@ -66,17 +72,17 @@ var
line: String; line: String;
fg, bg: Byte; fg, bg: Byte;
begin begin
if HasOption('h', 'help') or (not HasOption('c', 'commandfile') and not if HasOption('h', 'help') or (not HasOption(OPT_COMMANDFILE) and not
HasOption('s', 'simple')) then HasOption(OPT_SIMPLE)) then
begin begin
WriteHelp; WriteHelp;
Terminate; Terminate;
Exit; Exit;
end; end;
if HasOption('c', 'commandfile') then if HasOption(OPT_COMMANDFILE) then
begin begin
FCommandFileName := GetOptionValue('c', 'commandfile'); FCommandFileName := GetOptionValue(OPT_COMMANDFILE);
if not FileExists(FCommandFileName) then if not FileExists(FCommandFileName) then
begin begin
@ -100,9 +106,9 @@ begin
CloseFile(commandFile); CloseFile(commandFile);
end; //commandfile processing end; //commandfile processing
if HasOption('s', 'simple') then if HasOption(OPT_SIMPLE) then
begin begin
FCurrentLineFilter := TLineFilter.Create(GetOptionValue('s', 'simple')); FCurrentLineFilter := TLineFilter.Create(GetOptionValue(OPT_SIMPLE));
FLineFilters.Add(FCurrentLineFilter); FLineFilters.Add(FCurrentLineFilter);
if HasOption('fg') then if HasOption('fg') then
@ -118,8 +124,8 @@ begin
FCurrentLineFilter.Filters.Add(THighlightFilter.Create('.*', fg, bg, 0)); FCurrentLineFilter.Filters.Add(THighlightFilter.Create('.*', fg, bg, 0));
end; //Simple Mode end; //Simple Mode
if HasOption('f', 'logfile') then if HasOption(OPT_LOGFILE) then
FLogFileName := GetOptionValue('f', 'logfile'); FLogFileName := GetOptionValue(OPT_LOGFILE);
if not FileExists(FLogFileName) then if not FileExists(FLogFileName) then
begin begin