Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 110 lines (84 sloc) 2.845 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
1313d67 Cristi Burcă fix pear package; set version to 0.3.0
scribu authored
7 define( 'WP_CLI_VERSION', '0.3.0' );
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'] );
441ae70 Cristi Burcă look for a wp-cli-blog file when --blog is not set
scribu authored
52 } elseif ( is_readable( WP_ROOT . '/wp-cli-blog' ) ) {
53 $blog = file_get_contents( WP_ROOT . '/wp-cli-blog' );
54 }
55
56 if ( isset( $blog ) ) {
53e31d5 Cristi Burcă fix warning when --blog does not contain trailing slash
scribu authored
57 if ( false === strpos( $blog, '/' ) )
58 $blog .= '/';
59
441ae70 Cristi Burcă look for a wp-cli-blog file when --blog is not set
scribu authored
60 list( $domain, $path ) = explode( '/', $blog, 2 );
4d700f9 Cristi Burcă handle --blog parameter
scribu authored
61
62 $_SERVER['HTTP_HOST'] = $domain;
63
64 $_SERVER['REQUEST_URI'] = '/' . $path;
65 }
66
67 // Load WordPress libs
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
68 require_once(WP_ROOT . 'wp-load.php');
69 require_once(ABSPATH . 'wp-admin/includes/admin.php');
70
1e2b9ee Andreas Creten Documentation and command line tools
authored
71 // Load all internal commands
475589a Andreas Creten PHP version check and globalization
authored
72 foreach (glob(WP_CLI_ROOT.'/commands/internals/*.php') as $filename) {
368f281 Andreas Creten Removed todo's from readme
authored
73 include $filename;
1e2b9ee Andreas Creten Documentation and command line tools
authored
74 }
75
76 // Load all plugin commands
475589a Andreas Creten PHP version check and globalization
authored
77 foreach (glob(WP_CLI_ROOT.'/commands/community/*.php') as $filename) {
368f281 Andreas Creten Removed todo's from readme
authored
78 include $filename;
f6ec437 Andreas Creten New general structure
authored
79 }
80
f6abf48 Cristi Burcă check if there are any commands before doing anything with the args
scribu authored
81 // Check if there are commands installed
82 if(empty(WP_CLI::$commands)) {
83 WP_CLI::error('No commands installed');
84 WP_CLI::line();
85 WP_CLI::line('Visit the wp-cli page on github on more information on how to install commands.');
86 exit();
87 }
88
3e9074e Cristi Burcă provide completions for sub-commands. see #6
scribu authored
89 // Handle --completions parameter
90 if ( isset( $assoc_args['completions'] ) ) {
91 foreach ( WP_CLI::$commands as $name => $command ) {
59cad82 Cristi Burcă rename get_methods() to get_subcommands()
scribu authored
92 WP_CLI::line( $name . ' ' . implode( ' ', WP_CLI_Command::get_subcommands($command) ) );
3e9074e Cristi Burcă provide completions for sub-commands. see #6
scribu authored
93 }
94 exit;
95 }
96
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
97 // Get the top-level command
b60273e Cristi Burcă default to 'help' command again when no arguments are passed
scribu authored
98 if ( empty( $arguments ) )
99 $command = 'help';
100 else
101 $command = array_shift( $arguments );
f6ec437 Andreas Creten New general structure
authored
102
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
103 if ( !isset( WP_CLI::$commands[$command] ) ) {
e32684c Cristi Burcă introduce help command. fixes #22
scribu authored
104 WP_CLI::error( "'$command' is not a registered wp command. See 'wp help'." );
105 exit;
f6abf48 Cristi Burcă check if there are any commands before doing anything with the args
scribu authored
106 }
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
107
48a8887 Cristi Burcă make help method static; revert to __construct() instead of dispatch()
scribu authored
108 new WP_CLI::$commands[$command]( $arguments, $assoc_args );
859ca44 Cristi Burcă introduce WP_CLI::parse_args()
scribu authored
109
Something went wrong with that request. Please try again.