-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPythonFMXBuilderEntityEditor.dpr
More file actions
117 lines (102 loc) · 2.72 KB
/
PythonFMXBuilderEntityEditor.dpr
File metadata and controls
117 lines (102 loc) · 2.72 KB
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
program PythonFMXBuilderEntityEditor;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
FMX.Forms,
VSoft.CommandLine.Options,
Builder.Services,
Builder.Services.Factory,
Cli.Exception,
Form.Environment in 'source\views\Form.Environment.pas',
Form.Project in 'source\views\Form.Project.pas';
type
TProjectOptions = class
public
class var
ProjectNameCommand: string;
end;
procedure ConfigureEnvironmentOptions();
begin
var LCmd := TOptionsRegistry.RegisterCommand(
'environment',
String.Empty,
'Edit the environment.',
String.Empty,
'environment [options]');
LCmd.Examples.Add('environment');
end;
procedure ConfigureProjectOptions();
begin
var LCmd := TOptionsRegistry.RegisterCommand(
'project',
String.Empty,
'Edit a project.',
String.Empty,
'project [options]');
var LOption := LCmd.RegisterOption<string>(
'name',
String.Empty,
'Project name.',
procedure(const AValue: string) begin
TProjectOptions.ProjectNameCommand := AValue;
end);
LOption.Required := true;
LCmd.Examples.Add('project --name my_project');
end;
procedure ConfigureOptions();
begin
TOptionsRegistry.DescriptionTab := 35;
TOptionsRegistry.NameValueSeparator := ' ';
ConfigureEnvironmentOptions();
ConfigureProjectOptions();
end;
procedure ConfigureForm(const AForm: TForm);
begin
AForm.Position := TFormPosition.MainFormCenter;
end;
begin
ConfigureOptions();
try
var LParsed := TOptionsRegistry.Parse();
if LParsed.HasErrors then begin
Writeln;
Writeln(LParsed.ErrorText);
TOptionsRegistry.PrintUsage(String.Empty,
procedure(const AValue: string) begin
WriteLn(AValue);
end);
Exit;
end;
if (LParsed.Command = 'environment') then begin
var LForm := TEnvironmentForm.Create(nil);
try
ConfigureForm(LForm);
LForm.ShowModal();
finally
LForm.Free();
end;
end else if (LParsed.Command = 'project') then begin
var LService := TServiceSimpleFactory.CreateProject();
if not LService.HasProject(TProjectOptions.ProjectNameCommand) then
raise EProjectNotFound.Create(TProjectOptions.ProjectNameCommand);
var LForm := TProjectForm.Create(nil);
try
ConfigureForm(LForm);
LForm.Id := TProjectOptions.ProjectNameCommand;
LForm.ShowModal();
finally
LForm.Free();
end;
end;
except
on E: ECliException do begin
WriteLn(E.Message);
ExitCode := E.Code;
end;
on E: Exception do begin
Writeln(E.Message);
ExitCode := 1;
end;
end;
end.