Made commandline more verbose

This commit is contained in:
Andreas Schneider 2015-09-24 14:26:00 +02:00
parent c9b6b19479
commit b2ff58af6e
1 changed files with 46 additions and 5 deletions

View File

@ -49,6 +49,8 @@ type
FLineFilters: TLineFilters;
FCurrentLineFilter: TLineFilter;
FCommandMatcher: TRegExpr;
FCommandFileName: String;
FLogFileName: String;
procedure DoRun; override;
procedure ProcessCommand(ACommand, AParams: String);
procedure WriteContent(AContent: String; AFilters: TFilterList;
@ -87,10 +89,25 @@ var
lineFilter: TLineFilter;
line: String;
begin
AssignFile(commandFile, ParamStr(1));
if HasOption('h', 'help') or not HasOption('c', 'commandfile') then
begin
WriteHelp;
Terminate;
Exit;
end;
FCommandFileName := GetOptionValue('c', 'commandfile');
if not FileExists(FCommandFileName) then
begin
Writeln('Commandfile not found: ', FCommandFileName);
ExitCode := 1;
Terminate;
Exit;
end;
AssignFile(commandFile, FCommandFileName);
Reset(commandFile);
AssignFile(logFile, ParamStr(2));
Reset(logFile);
// Parse command file first
while not EOF(commandFile) do
@ -100,6 +117,19 @@ begin
ProcessCommand(FCommandMatcher.Match[1], FCommandMatcher.Match[3]);
end;
CloseFile(commandFile);
if not FileExists(FLogFileName) then
begin
Writeln('Logfile not found: ', FLogFileName);
ExitCode := 1;
Terminate;
Exit;
end;
AssignFile(logFile, FLogFileName);
Reset(logFile);
// Filter log
while not EOF(logFile) do
begin
@ -111,7 +141,6 @@ begin
end;
end;
CloseFile(commandFile); //TODO: narrow scope!
CloseFile(logFile);
Terminate;
@ -132,6 +161,10 @@ begin
highlightFilter := THighlightFilter.Create(AParams);
FCurrentLineFilter.Filters.Add(highlightFilter);
end;
'file':
begin
FLogFileName := AParams;
end;
end;
end;
@ -235,7 +268,15 @@ end;
procedure TLogFilterApplication.WriteHelp;
begin
Writeln('Usage: ', ExtractFileName(ExeName), ' [options]');
Writeln;
Writeln('Options:');
Writeln(' -c --commandfile=<filename>');
Writeln(' specifies the filename with filter commands');
Writeln(' -f --logfile=<filename>');
Writeln(' specifies the logfile to be parsed');
Writeln(' -h --help');
Writeln(' show this help screen');
end;
end.