-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtasks.stag.php
executable file
·59 lines (48 loc) · 1.54 KB
/
tasks.stag.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
<?php
class Tasks_stag extends Tasks {
public $commands = array();
public $show_command_line_output = true;
public function run($method, $options = array()) {
if ($method == null) {
$this->handleNoCommandGiven();
}
$filename = __DIR__ . "/commands/command.$method.php";
if (File::exists($filename)) {
$klass = $this->classify($method);
$obj = new $klass($this->config);
$obj->run($options);
} else {
$this->handleCommandNotFound($method);
}
}
public function displayFeedback($message) {
if ($this->show_command_line_output) {
fwrite(STDOUT, "$message\n\n");
}
}
private function classify($str) {
return ucwords(Helper::camelCase($str));
}
private function handleNoCommandGiven() {
$output = <<<EOF
______ _________ _ ______
{__} .' ____ \ | _ _ | / \ .' ___ | {__}
\/_____! | (___ \_| |_/ | | \_| / _ \ / .' \_| !_____\/
\----| _.____`. | | / ___ \ | | ____ |----/
/| |\ | \____) | _| |_ _/ / \ \_ \ `.___] | /| |\
\______.' |_____| |____| |____| `._____.'
Stag lets you Statamic-it-up on the command line.
Usage: stag <command> <options>
Try stag help to list all commands.
EOF;
$this->displayFeedback($output);
exit(1);
}
private function handleCommandNotFound($cmd) {
$output = <<<EOF
I don't know how to $cmd. Would you like to teach me?
EOF;
$this->displayFeedback($output);
exit(1);
}
}