This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ConsoleRunner.pas
129 lines (110 loc) · 3.37 KB
/
ConsoleRunner.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{**
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
**}
unit ConsoleRunner;
interface
uses Classes, PackageInfo, CompilationData, ConsoleProgressMonitor;
type
TConsoleRunner = class
private
fCompilationData: TCompilationData;
fMonitor: TConsoleProgressMonitor;
fOutputLevel: TConsoleOutputLevel;
fScriptFile: String;
procedure DisplayHelp;
protected
procedure DisplayHeader; virtual;
procedure ParseArguments;virtual;
public
procedure Run;
property OutputLevel: TConsoleOutputLevel read fOutputLevel;
end;
implementation
uses SysUtils, gnugettext, MonitoredPackageCompiler, ScriptPersister, PackageCompiler,
Utils, JclConsole, StrUtils;
procedure WriteLine(color: TJclScreenFontColor; text: string);
begin
TJclConsole.Default.ActiveScreen.Writeln(text, TJclScreenTextAttribute.Create(color));
end;
{ TConsoleRunner }
//TODO Refactor this
procedure TConsoleRunner.Run;
var
scripter : TScriptPersister;
packageCompiler: TMonitoredPackageCompiler;
begin
DisplayHeader;
try
ParseArguments;
except
on ex : Exception do begin
WriteLine(fclRed, ex.Message);
DisplayHelp;
exit;
end;
end;
scripter := TScriptPersister.Create;
try
fCompilationData := scripter.Load(fScriptFile);
fMonitor := TConsoleProgressMonitor.Create;
fMonitor.OutputLevel := Self.OutputLevel;
finally
scripter.Free;
end;
packageCompiler := TMonitoredPackageCompiler.Create(fCompilationData, fMonitor);
try
packageCompiler.Compile;
finally
packageCompiler.Free;
end;
end;
procedure TConsoleRunner.DisplayHeader;
begin
WriteLine(fclWhite, 'DelphiPI Console ' + Utils.VERSION);
WriteLine(fclWhite, 'By ' + Utils.AUTHOR);
end;
procedure TConsoleRunner.DisplayHelp;
begin
WriteLine(fclWhite, 'Usage:');
WriteLine(fclWhite, 'DelphiPIConsole.exe [ScriptFile] [OutputLevel]');
WriteLine(fclWhite, 'ScriptFile : script file saved by the DelphiPI which contains necessary information about compilation');
WriteLine(fclWhite, 'OutputLevel: during compilation how much info should be displayed');
WriteLine(fclWhite, #9'0 means silent');
WriteLine(fclWhite, #9'1 means brief');
WriteLine(fclWhite, #9'2 means full');
end;
procedure TConsoleRunner.ParseArguments;
var
i:integer;
param: string;
begin
fOutputLevel := TConsoleOutputLevel.colBrief;
if ParamCount = 0 then
raise Exception.Create('Requires Script File.');
fScriptFile := ParamStr(1);
if not FileExists(fScriptFile) then
raise Exception.Create('File does not exist: ' + fScriptFile);
i := 2;
while i < ParamCount do
begin
param := UpperCase(ParamStr(i));
// Logging level
// if param = '-L' then
// begin
// i := i+1;
// param := UpperCase(ParamStr(i));
if (param = '0') or (param = 'SILENT') then
fOutputLevel := TConsoleOutputLevel.colSilent
else if (param='1') or (param = 'BRIEF') then
fOutputLevel := TConsoleOutputLevel.colBrief
else if (param='2') or (param = 'FULL') then
fOutputLevel := TConsoleOutputLevel.colFull
else
raise Exception.Create(param + ' is not a valid value for OutputLogLevel');
end;
//
// end;
end;
end.