-
Notifications
You must be signed in to change notification settings - Fork 68
/
command.php
186 lines (146 loc) · 3.94 KB
/
command.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* Fuel is a fast, lightweight, community driven PHP5 framework.
*
* @package Fuel
* @version 1.0
* @author Fuel Development Team
* @license MIT License
* @copyright 2010 - 2011 Fuel Development Team
* @link http://fuelphp.com
*/
namespace Oil;
/**
* Oil\Cli Class
*
* @package Fuel
* @subpackage Oil
* @category Core
* @author Phil Sturgeon
*/
class Command
{
public static function init($args)
{
// Remove flag options from the main argument list
for ($i =0; $i < count($args); $i++)
{
if (strpos($args[$i], '-') === 0)
{
unset($args[$i]);
}
}
try
{
if ( ! isset($args[1]))
{
if (\Cli::option('v', \Cli::option('version')))
{
\Cli::write('Fuel: ' . \Fuel::VERSION);
return;
}
static::help();
return;
}
switch ($args[1])
{
case 'g':
case 'generate':
$action = isset($args[2]) ? $args[2]: 'help';
$subfolder = 'default';
if (is_int(strpos($action, 'scaffold/')))
{
$subfolder = str_replace('scaffold/', '', $action);
$action = 'scaffold';
}
switch ($action)
{
case 'controller':
case 'model':
case 'views':
case 'migration':
call_user_func('Oil\Generate::'.$action, array_slice($args, 3));
break;
case 'scaffold':
call_user_func('Oil\Scaffold::generate', array_slice($args, 3), $subfolder);
break;
default:
Generate::help();
}
break;
case 'c':
case 'console':
new Console;
case 'r':
case 'refine':
// Developers of third-party tasks may not be displaying PHP errors. Report any error and quit
set_error_handler(function($errno, $errstr, $errfile, $errline){
\Cli::error("Error: {$errstr} in $errfile on $errline");
\Cli::beep();
exit;
});
$task = isset($args[2]) ? $args[2] : null;
call_user_func('Oil\Refine::run', $task, array_slice($args, 3));
break;
case 'p':
case 'package':
$action = isset($args[2]) ? $args[2]: 'help';
switch ($action)
{
case 'install':
case 'uninstall':
call_user_func_array('Oil\Package::'.$action, array_slice($args, 3));
break;
default:
Package::help();
}
break;
case 't':
case 'test':
// Suppressing this because if the file does not exist... well thats a bad thing and we can't really check
// I know that supressing errors is bad, but if you're going to complain: shut up. - Phil
@include_once('PHPUnit/Autoload.php');
// Attempt to load PHUnit. If it fails, we are done.
if ( ! class_exists('PHPUnit_Framework_TestCase'))
{
throw new Exception('PHPUnit does not appear to be installed.'.PHP_EOL.PHP_EOL."\tPlease visit http://phpunit.de and install.");
}
// CD to the root of Fuel and call up phpunit with a path to our config
$command = 'cd '.DOCROOT.'; phpunit -c "'.COREPATH.'phpunit.xml"';
// Respect the group option
\Cli::option('group') and $command .= ' --group '.\Cli::option('group');
// Respect the coverage-html option
\Cli::option('coverage-html') and $command .= ' --coverage-html '.\Cli::option('coverage-html');
foreach(explode(';', $command) as $c)
{
passthru($c);
}
break;
default:
static::help();
}
}
catch (Exception $e)
{
\Cli::error('Error: '.$e->getMessage());
\Cli::beep();
}
}
public static function help()
{
echo <<<HELP
Usage:
php oil [console|generate|help|test|package]
Runtime options:
-f, [--force] # Overwrite files that already exist
-s, [--skip] # Skip files that already exist
-q, [--quiet] # Supress status output
Description:
The 'oil' command can be used in several ways to facilitate quick development, help with
testing your application and for running Tasks.
Documentation:
http://fuelphp.com/docs/packages/oil/intro.html
HELP;
}
}
/* End of file oil/classes/cli.php */