Scaffold::plugin( $args,  $assoc_args )

Plugin scaffold command.


Description Description

Top ↑

OPTIONS OPTIONS

: The slug of the BuddyPress plugin.
[–force] : Whether to overwrite files.
## EXAMPLES
$ wp bp scaffold tests sample-test Success: Created BuddyPress test files.
$ wp bp scaffold tests another-ssample-test Success: Created BuddyPress test files.


Source Source

File: cli/src/scaffold.php

	public function plugin( $args, $assoc_args ) {
		$wp_filesystem = $this->init_wp_filesystem();
		$target_dir    = WP_PLUGIN_DIR . "/{$args[0]}";

		if ( ! is_dir( $target_dir ) ) {
			WP_CLI::error( "Invalid plugin slug specified. No such target directory '{$target_dir}'." );
		}

		$error_msg = $this->check_target_directory( $target_dir );
		if ( ! empty( $error_msg ) ) {
			WP_CLI::error( "Invalid plugin slug specified. {$error_msg}" );
		}

		$to_copy = array(
			'install-bp-tests.sh'      => "{$target_dir}/bin",
			'bootstrap-buddypress.php' => "{$target_dir}/tests",
		);

		foreach ( $to_copy as $file => $dir ) {
			$file_name = "$dir/$file";

			$prompt = WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );

			// Prompt it.
			$should_write_file = $this->prompt_if_files_will_be_overwritten( $file_name, $prompt );

			if ( false === $should_write_file ) {
				continue;
			}

			$files_written[] = $file_name;

			$wp_filesystem->copy( self::get_template_path( $file ), $file_name, true );

			if ( 'install-bp-tests.sh' === $file ) {
				if ( ! $wp_filesystem->chmod( "$dir/$file", 0755 ) ) {
					WP_CLI::warning( "Couldn't mark 'install-bp-tests.sh' as executable." );
				}
			}
		}

		$this->log_whether_files_written(
			$files_written,
			'All BuddyPress test files were skipped.',
			'Created BuddyPress test files.'
		);
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.