Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 111 lines (87 sloc) 2.959 kb
6f56aca Andreas Creten First implementation of the CLI, focussed on plugin actions
authored
1 <?php
2
f6ec437 Andreas Creten New general structure
authored
3 if(PHP_SAPI !== 'cli') {
4 die('Only cli access');
5 }
6
9336167 Cristi Burcă bump version to 0.4.0-dev
scribu authored
7 define( 'WP_CLI_VERSION', '0.4.0-dev' );
475589a Andreas Creten PHP version check and globalization
authored
8
9 // Define the wp-cli location
9f1289b Cristi Burcă re-organize files
scribu authored
10 define( 'WP_CLI_ROOT', __DIR__ . '/' );
6f56aca Andreas Creten First implementation of the CLI, focussed on plugin actions
authored
11
1e2b9ee Andreas Creten Documentation and command line tools
authored
12 // Set a constant that can be used to check if we are running wp-cli or not
13 define('WP_CLI', true);
14
15 // Include the wp-cli classes
9f1289b Cristi Burcă re-organize files
scribu authored
16 include WP_CLI_ROOT . 'class-wp-cli.php';
17 include WP_CLI_ROOT . 'class-wp-cli-command.php';
f6ec437 Andreas Creten New general structure
authored
18
8ca86dd Andreas Creten Updated the core to comply with the coding standards
authored
19 // Include the command line tools
1313d67 Cristi Burcă fix pear package; set version to 0.3.0
scribu authored
20 include WP_CLI_ROOT . '../php-cli-tools/lib/cli/cli.php';
8ca86dd Andreas Creten Updated the core to comply with the coding standards
authored
21
22 // Register the cli tools autoload
1e2b9ee Andreas Creten Documentation and command line tools
authored
23 \cli\register_autoload();
6f56aca Andreas Creten First implementation of the CLI, focussed on plugin actions
authored
24
9d222c3 Cristi Burcă add --version flag
scribu authored
25 // Get the cli arguments
26 list( $arguments, $assoc_args ) = WP_CLI::parse_args( array_slice( $GLOBALS['argv'], 1 ) );
27
28 // Handle --version parameter
29 if ( isset( $assoc_args['version'] ) ) {
30 WP_CLI::line( 'wp-cli ' . WP_CLI_VERSION );
31 exit;
32 }
33
34 // Define the WordPress location
35 if(is_readable($_SERVER['PWD'] . '/../wp-load.php')) {
36 define('WP_ROOT', $_SERVER['PWD'] . '/../');
37 }
38 else {
39 define('WP_ROOT', $_SERVER['PWD'] . '/');
40 }
41
1e2b9ee Andreas Creten Documentation and command line tools
authored
42 // Taken from https://github.com/88mph/wpadmin/blob/master/wpadmin.php
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
43 if ( !is_readable( WP_ROOT . 'wp-load.php' ) ) {
1e2b9ee Andreas Creten Documentation and command line tools
authored
44 WP_CLI::error('Either this is not a WordPress document root or you do not have permission to administer this site.');
368f281 Andreas Creten Removed todo's from readme
authored
45 exit();
1e2b9ee Andreas Creten Documentation and command line tools
authored
46 }
47
4d700f9 Cristi Burcă handle --blog parameter
scribu authored
48 // Handle --blog parameter
49 if ( isset( $assoc_args['blog'] ) ) {
441ae70 Cristi Burcă look for a wp-cli-blog file when --blog is not set
scribu authored
50 $blog = $assoc_args['blog'];
4d700f9 Cristi Burcă handle --blog parameter
scribu authored
51 unset( $assoc_args['blog'] );
05dc7a0 Cristi Burcă add usage example when --blog is used as a flag
scribu authored
52 if ( true === $blog ) {
53 WP_CLI::line( 'usage: wp --blog=example.com' );
54 }
6f36025 Cristi Burcă remove extra line endings from wp-cli-blog content
scribu authored
55 } elseif ( is_readable( WP_ROOT . 'wp-cli-blog' ) ) {
56 $blog = trim( file_get_contents( WP_ROOT . 'wp-cli-blog' ) );
441ae70 Cristi Burcă look for a wp-cli-blog file when --blog is not set
scribu authored
57 }
58
59 if ( isset( $blog ) ) {
159acd1 Cristi Burcă add necessary site_url parameter. see #51
scribu authored
60 WP_CLI::set_url( $blog );
4d700f9 Cristi Burcă handle --blog parameter
scribu authored
61 }
62
159acd1 Cristi Burcă add necessary site_url parameter. see #51
scribu authored
63 // Set installer flag before loading any WP files
930f1f0 Cristi Burcă prevent notice when checking for install sub-command
scribu authored
64 if ( count( $arguments ) >= 2 && $arguments[0] == 'core' && $arguments[1] == 'install' ) {
2b6d6f8 Michael Williamson Add installation commands
mwilliamson-red-gate authored
65 define( 'WP_INSTALLING', true );
66 }
67
4d700f9 Cristi Burcă handle --blog parameter
scribu authored
68 // Load WordPress libs
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
69 require_once(WP_ROOT . 'wp-load.php');
70 require_once(ABSPATH . 'wp-admin/includes/admin.php');
71
1e2b9ee Andreas Creten Documentation and command line tools
authored
72 // Load all internal commands
2dfe523 Cristi Burcă coding standards
scribu authored
73 foreach ( glob(WP_CLI_ROOT.'/commands/internals/*.php') as $filename ) {
368f281 Andreas Creten Removed todo's from readme
authored
74 include $filename;
1e2b9ee Andreas Creten Documentation and command line tools
authored
75 }
76
77 // Load all plugin commands
2dfe523 Cristi Burcă coding standards
scribu authored
78 foreach ( glob(WP_CLI_ROOT.'/commands/community/*.php') as $filename ) {
368f281 Andreas Creten Removed todo's from readme
authored
79 include $filename;
f6ec437 Andreas Creten New general structure
authored
80 }
81
f6abf48 Cristi Burcă check if there are any commands before doing anything with the args
scribu authored
82 // Check if there are commands installed
83 if(empty(WP_CLI::$commands)) {
84 WP_CLI::error('No commands installed');
85 WP_CLI::line();
86 WP_CLI::line('Visit the wp-cli page on github on more information on how to install commands.');
87 exit();
88 }
89
3e9074e Cristi Burcă provide completions for sub-commands. see #6
scribu authored
90 // Handle --completions parameter
91 if ( isset( $assoc_args['completions'] ) ) {
92 foreach ( WP_CLI::$commands as $name => $command ) {
59cad82 Cristi Burcă rename get_methods() to get_subcommands()
scribu authored
93 WP_CLI::line( $name . ' ' . implode( ' ', WP_CLI_Command::get_subcommands($command) ) );
3e9074e Cristi Burcă provide completions for sub-commands. see #6
scribu authored
94 }
95 exit;
96 }
97
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
98 // Get the top-level command
b60273e Cristi Burcă default to 'help' command again when no arguments are passed
scribu authored
99 if ( empty( $arguments ) )
100 $command = 'help';
101 else
102 $command = array_shift( $arguments );
f6ec437 Andreas Creten New general structure
authored
103
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
104 if ( !isset( WP_CLI::$commands[$command] ) ) {
e32684c Cristi Burcă introduce help command. fixes #22
scribu authored
105 WP_CLI::error( "'$command' is not a registered wp command. See 'wp help'." );
106 exit;
f6abf48 Cristi Burcă check if there are any commands before doing anything with the args
scribu authored
107 }
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
108
48a8887 Cristi Burcă make help method static; revert to __construct() instead of dispatch()
scribu authored
109 new WP_CLI::$commands[$command]( $arguments, $assoc_args );
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
110
Something went wrong with that request. Please try again.