|
4 | 4 | return;
|
5 | 5 | }
|
6 | 6 |
|
7 |
| -require_once( dirname( __FILE__ ) . "/lib/functions.php" ); |
8 |
| - |
9 |
| -/** |
10 |
| - * Generate a new VCCW environment. |
11 |
| - * |
12 |
| - * @subpackage commands/community |
13 |
| - * @maintainer Takayuki Miyauchi |
14 |
| - */ |
15 |
| -class WP_CLI_Scaffold_VCCW extends WP_CLI_Command |
16 |
| -{ |
17 |
| - /** |
18 |
| - * Generate a new VCCW environment. |
19 |
| - * |
20 |
| - * ## OPTIONS |
21 |
| - * |
22 |
| - * <directory> |
23 |
| - * : The directory of the new VCCW based guest machine. |
24 |
| - * |
25 |
| - * [--host=<hostname>] |
26 |
| - * : Hostname of the guest machine. Default is `vccw.dev`. |
27 |
| - * |
28 |
| - * [--ip=<ip-address>] |
29 |
| - * : IP address of the guest machine. Default is `192.168.33.10`. |
30 |
| - * |
31 |
| - * [--lang=<language>] |
32 |
| - * : Language of the WordPress. Default is `en_US`. |
33 |
| - * |
34 |
| - * [--update] |
35 |
| - * : Update files of the VCCW to latest version. |
36 |
| - * |
37 |
| - * ## EXAMPLES |
38 |
| - * |
39 |
| - * $ wp scaffold vccw wordpress.dev |
40 |
| - * Generating: 100% [===========================] 0:03 / 0:06 |
41 |
| - * Success: Generated. |
42 |
| - * |
43 |
| - * $ wp scaffold vccw wordpress.dev --lang=ja |
44 |
| - * Generating: 100% [===========================] 0:03 / 0:06 |
45 |
| - * Success: Generated. |
46 |
| - * |
47 |
| - * @when before_wp_load |
48 |
| - */ |
49 |
| - public function __invoke( $args, $assoc_args ) |
50 |
| - { |
51 |
| - if ( empty( $assoc_args["host"] ) ) { |
52 |
| - $assoc_args["host"] = "vccw.dev"; |
53 |
| - } |
54 |
| - |
55 |
| - if ( empty( $assoc_args["ip"] ) ) { |
56 |
| - $assoc_args["ip"] = "192.168.33.10"; |
57 |
| - } |
58 |
| - |
59 |
| - if ( empty( $assoc_args["lang"] ) ) { |
60 |
| - $assoc_args["lang"] = "en_US"; |
61 |
| - } |
62 |
| - |
63 |
| - $update = \WP_CLI\Utils\get_flag_value( $assoc_args, 'update' ); |
64 |
| - |
65 |
| - $path = preg_replace( "#/$#", "", $args[0] ); |
66 |
| - if ( is_file( $path . '/site.yml' ) && true !== $update ) { |
67 |
| - WP_CLI::error( "`site.yml` already exists." ); |
68 |
| - } |
69 |
| - |
70 |
| - $url = Scaffold_VCCW::get_latest_vccw_url(); |
71 |
| - if ( ! $url ) { |
72 |
| - WP_CLI::error( "Can't connect GitHub's API. Please try later." ); |
73 |
| - } |
74 |
| - |
75 |
| - $zip = Scaffold_VCCW::download( $url ); |
76 |
| - if ( ! $zip ) { |
77 |
| - WP_CLI::error( "Can't download zip. Please try later." ); |
78 |
| - } |
79 |
| - |
80 |
| - $file = tempnam( sys_get_temp_dir(), "" ); |
81 |
| - file_put_contents( $file, $zip ); |
82 |
| - |
83 |
| - try { |
84 |
| - $dir = Scaffold_VCCW::tempdir(); |
85 |
| - Scaffold_VCCW::unzip( $file, $dir ); |
86 |
| - } catch (Exception $e) { |
87 |
| - Scaffold_VCCW::rrmdir( $dir ); |
88 |
| - WP_CLI::error( $e->getMessage() ); |
89 |
| - } |
90 |
| - |
91 |
| - if ( is_dir( $dir ) ) { |
92 |
| - if ( $dh = opendir( $dir ) ) { |
93 |
| - while ( ( $file = readdir( $dh ) ) !== false ) { |
94 |
| - $src = $dir . "/" . $file; |
95 |
| - if ( preg_match( "/^vccw/", $file ) && is_dir( $src ) ) { |
96 |
| - Scaffold_VCCW::rcopy( $src, $path ); |
97 |
| - break; |
98 |
| - } |
99 |
| - } |
100 |
| - closedir( $dh ); |
101 |
| - } |
102 |
| - } |
103 |
| - |
104 |
| - Scaffold_VCCW::rrmdir( $dir ); |
105 |
| - |
106 |
| - if ( true === $update ) { |
107 |
| - WP_CLI::success( "Updated. Run `vagrant up`." ); |
108 |
| - } else { |
109 |
| - $sitefile = WP_CLI\Utils\mustache_render( |
110 |
| - Scaffold_VCCW::get_yml_template(), |
111 |
| - array( |
112 |
| - 'host' => $assoc_args["host"], |
113 |
| - 'ip' => $assoc_args["ip"], |
114 |
| - 'lang' => $assoc_args["lang"], |
115 |
| - ) |
116 |
| - ); |
117 |
| - file_put_contents( $path . '/site.yml', $sitefile ); |
118 |
| - WP_CLI::success( "Generated. Run `vagrant up`." ); |
119 |
| - } |
120 |
| - } |
| 7 | +$autoload = dirname( __FILE__ ) . '/vendor/autoload.php'; |
| 8 | +if ( file_exists( $autoload ) ) { |
| 9 | + require_once $autoload; |
121 | 10 | }
|
122 | 11 |
|
123 |
| -WP_CLI::add_command( 'scaffold vccw', 'WP_CLI_Scaffold_VCCW' ); |
| 12 | +WP_CLI::add_command( 'scaffold vccw', 'Scaffold_VCCW_Command' ); |
0 commit comments