-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.dpr
89 lines (78 loc) · 2.16 KB
/
todo.dpr
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
program todo;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
uCommands in 'uCommands.pas',
uModel in 'uModel.pas',
uDatabase in 'uDatabase.pas';
function FindCmdLineSwitch2(AShortSwitch,
ALongSwitch: string): boolean;
begin
Result := False;
if (AShortSwitch <> '') then
Result := FindCmdLineSwitch(AShortSwitch);
if (not Result) and (ALongSwitch <> '') then
Result := FindCmdLineSwitch(ALongSwitch);
end;
function FindCmdLineSwitch3(AShortSwitch,
ALongSwitch: string;
var AValue: string): boolean;
begin
Result := False;
if (AShortSwitch <> '') then
Result := FindCmdLineSwitch(AShortSwitch, AValue);
if (not Result) and (ALongSwitch <> '') then
Result := FindCmdLineSwitch(ALongSwitch, AValue);
end;
var
LArgText: string;
LToDo: TToDoCommand;
begin
try
LToDo := TToDoCommand.Create;
if FindCmdLineSwitch3('i', 'add', LArgText) then
begin
if LArgText = '' then
begin
WriteLn('Missing description of item to add');
Exit;
end;
LToDo.AddItem(LArgText)
end
else if FindCmdLineSwitch2('l', 'list') then
LToDo.List(False)
else if FindCmdLineSwitch2('la', 'listall') then
LToDo.List(True)
else if FindCmdLineSwitch3('x', 'done', LArgText) then
begin
if LArgText = '' then
begin
WriteLn('Missing items to update');
Exit;
end;
LToDo.Complete(LArgText);
end
else if FindCmdLineSwitch3('d', 'delete', LArgText) then
begin
if LArgText = '' then
begin
WriteLn('Missing items to delete');
Exit;
end;
LToDo.Delete(LArgText);
end
else if FindCmdLineSwitch2('s', 'sort') then
LToDo.Sort
else if FindCmdLineSwitch2('t', 'touch') then
LToDo.Touch
else if FindCmdLineSwitch2('a', 'archive') then
LToDo.Archive
else if FindCmdLineSwitch2('sd', 'summary-daily') then
LToDo.GetSummary;
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.