-
Notifications
You must be signed in to change notification settings - Fork 0
/
t.php
66 lines (54 loc) · 1.27 KB
/
t.php
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
<?php
/*
* This file is part of the todoList package.
*
* (c) Benjamin LAZARECKI <[email protected]>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/
/**
* todoList
*
* Allow you to manage your todolist.
* You can add / remove tasks.
*
* @author Benjamin Lazarecki <[email protected]>
*/
include __DIR__ . '/vendor/autoload.php';
// --- Init ---
$todoList = new TodoList\Base\TodoList();
$todoList->getFilesystem()->setPath(__DIR__ . '/todo.list');
try {
$todoList->getFilesystem()->check();
} catch (\Exception $e) {
fwrite(STDOUT, $e->getMessage());
die();
}
$todoList->init();
// --- Display all tasks ---
if (count($argv) === 1) {
fwrite(STDOUT, $todoList->display());
exit(0);
}
$options = getopt('r:');
// --- Add a task ---
if (count($options) == 0) {
$todoList
->addTask(array_slice($argv, 1))
->save();
exit(0);
}
// --- Remove a task ---
$id = $options['r'];
if ($id != null) {
try {
$todoList->removeTask($id);
} catch (\Exception $e) {
fwrite(STDOUT, $e->getMessage());
die();
}
$todoList->save();
fwrite(STDOUT, sprintf('Task %s deleted.%s', $id, PHP_EOL));
exit(0);
}