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
{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 }
procedure TLogFilterApplication.DoRun;
@ -66,17 +72,17 @@ var
line: String;
fg, bg: Byte;
begin
if HasOption('h', 'help') or (not HasOption('c', 'commandfile') and not
HasOption('s', 'simple')) then
if HasOption('h', 'help') or (not HasOption(OPT_COMMANDFILE) and not
HasOption(OPT_SIMPLE)) then
begin
WriteHelp;
Terminate;
Exit;
end;
if HasOption('c', 'commandfile') then
if HasOption(OPT_COMMANDFILE) then
begin
FCommandFileName := GetOptionValue('c', 'commandfile');
FCommandFileName := GetOptionValue(OPT_COMMANDFILE);
if not FileExists(FCommandFileName) then
begin
@ -100,9 +106,9 @@ begin
CloseFile(commandFile);
end; //commandfile processing
if HasOption('s', 'simple') then
if HasOption(OPT_SIMPLE) then
begin
FCurrentLineFilter := TLineFilter.Create(GetOptionValue('s', 'simple'));
FCurrentLineFilter := TLineFilter.Create(GetOptionValue(OPT_SIMPLE));
FLineFilters.Add(FCurrentLineFilter);
if HasOption('fg') then
@ -118,8 +124,8 @@ begin
FCurrentLineFilter.Filters.Add(THighlightFilter.Create('.*', fg, bg, 0));
end; //Simple Mode
if HasOption('f', 'logfile') then
FLogFileName := GetOptionValue('f', 'logfile');
if HasOption(OPT_LOGFILE) then
FLogFileName := GetOptionValue(OPT_LOGFILE);
if not FileExists(FLogFileName) then
begin