<commit_before><?php

WP_CLI:: add_command('rewrite', 'Rewrite_Command');

/**
 * Implement rewrite command
 *
 * @package	wp-cli
 * @subpackage	commands/internal
 */
class Rewrite_Command extends WP_CLI_Command {

	protected $aliases = array(
	);

	/**
	 * Flush rules
	 *
	 * @param array $args
	 * @param array $assoc_args
	 */
	public function flush( $args, $assoc_args ) {
		$hard = ( isset( $assoc_args['soft'] ) ) ? false : true;
		flush_rewrite_rules( $hard );
	}

	/**
	 * Set permalink structure
	 *
	 * @param array $args
	 * @param array $assoc_args
	 */
	public function structure( $args, $assoc_args ) {
		if ( !count( $args ) && !count( $assoc_args ) ) {
			WP_CLI::line( "usage: wp rewrite structure <new-permalink-structure>" );
			exit;
		}
		global $wp_rewrite;

		// copypasta from /wp-admin/options-permalink.php
		$home_path = get_home_path();
		$iis7_permalinks = iis7_supports_permalinks();

		$prefix = $blog_prefix = '';
		if ( ! got_mod_rewrite() && ! $iis7_permalinks )
			$prefix = '/index.php';
		if ( is_multisite() && !is_subdomain_install() && is_main_site() )
			$blog_prefix = '/blog';

		// Update base permastruct if argument is provided
		if ( isset( $args[0] ) ) {

			$permalink_structure = ( $args[0] == 'default' ) ? '' : $args[0];

			if ( ! empty( $permalink_structure ) ) {
				$permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
				if ( $prefix && $blog_prefix )
					$permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
				else
					$permalink_structure = $blog_prefix . $permalink_structure;
			}
			$wp_rewrite->set_permalink_structure( $permalink_structure );
		}

		// Update category or tag bases
		if ( isset( $assoc_args['category-base'] ) ) {

			$category_base = $assoc_args['category-base'];
			if ( ! empty( $category_base ) )
				$category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
			$wp_rewrite->set_category_base( $category_base );
		}

		if ( isset( $assoc_args['tag-base'] ) ) {

			$tag_base = $assoc_args['tag-base'];
			if ( ! empty( $tag_base ) )
				$tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
			$wp_rewrite->set_tag_base( $tag_base );
		}


		flush_rewrite_rules( $hard );
	}

	/**
	 * Dump rewrite rules
	 *
	 * @param none
	 */
	public function dump() {

		$rules = get_option( 'rewrite_rules' );

		foreach ( $rules as $route => $rule )
			WP_CLI::line( $route . "\t" . $rule );

	}
}

?><commit_msg>Add --json option to wp rewrite dump<commit_after><?php

WP_CLI:: add_command('rewrite', 'Rewrite_Command');

/**
 * Implement rewrite command
 *
 * @package	wp-cli
 * @subpackage	commands/internal
 */
class Rewrite_Command extends WP_CLI_Command {

	protected $aliases = array(
	);

	/**
	 * Flush rules
	 *
	 * @param array $args 		not used
	 * @param array $assoc_args --soft or --hard (default)
	 */
	public function flush( $args, $assoc_args ) {
		$hard = ( isset( $assoc_args['soft'] ) ) ? false : true;
		flush_rewrite_rules( $hard );
	}

	/**
	 * Set permalink structure
	 *
	 * @param array $args
	 * @param array $assoc_args
	 */
	public function structure( $args, $assoc_args ) {
		if ( !count( $args ) && !count( $assoc_args ) ) {
			WP_CLI::line( "usage: wp rewrite structure <new-permalink-structure>" );
			exit;
		}
		global $wp_rewrite;

		// copypasta from /wp-admin/options-permalink.php
		$home_path = get_home_path();
		$iis7_permalinks = iis7_supports_permalinks();

		$prefix = $blog_prefix = '';
		if ( ! got_mod_rewrite() && ! $iis7_permalinks )
			$prefix = '/index.php';
		if ( is_multisite() && !is_subdomain_install() && is_main_site() )
			$blog_prefix = '/blog';

		// Update base permastruct if argument is provided
		if ( isset( $args[0] ) ) {

			$permalink_structure = ( $args[0] == 'default' ) ? '' : $args[0];

			if ( ! empty( $permalink_structure ) ) {
				$permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
				if ( $prefix && $blog_prefix )
					$permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
				else
					$permalink_structure = $blog_prefix . $permalink_structure;
			}
			$wp_rewrite->set_permalink_structure( $permalink_structure );
		}

		// Update category or tag bases
		if ( isset( $assoc_args['category-base'] ) ) {

			$category_base = $assoc_args['category-base'];
			if ( ! empty( $category_base ) )
				$category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
			$wp_rewrite->set_category_base( $category_base );
		}

		if ( isset( $assoc_args['tag-base'] ) ) {

			$tag_base = $assoc_args['tag-base'];
			if ( ! empty( $tag_base ) )
				$tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
			$wp_rewrite->set_tag_base( $tag_base );
		}


		flush_rewrite_rules( $hard );
	}

	/**
	 * Dump rewrite rules
	 *
	 * @param array $args
	 * @param array $assoc_args
	 */
	public function dump( $args, $assoc_args ) {

		$rules = get_option( 'rewrite_rules' );

		if ( isset( $assoc_args['json'] ) )
			echo json_encode( $rules );
		else
			foreach ( $rules as $route => $rule )
				WP_CLI::line( $route . "\t" . $rule );

	}
}
{'fraction_non_alphanumeric': 0.1801160831304999, 'fraction_numerical': 0.0022467702677401234, 'mean_word_length': 3.4777870913663036, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '969151', 'n_tokens_mistral': 2182, 'n_tokens_neox': 1949, 'n_words': 381}