<commit_before><?php

WP_CLI::addCommand('user', 'UserCommand');

/**
 * Implement user command
 *
 * @package wp-cli
 * @subpackage commands/internals
 */
class UserCommand extends WP_CLI_Command {
  /**
   * List users
   * 
   * @param array $args
	 * @param array $assoc_args
   **/
  public function all( $args, $assoc_args ) {
    global $blog_id;

    $users = get_users("blog_id=$blog_id");
    $fields = array('ID', 'user_login', 'display_name', 'user_email',
      'user_registered', 'user_status');
    $table = new \cli\Table();
    $table->setHeaders($fields);

    foreach ( $users as $user ) {
      $line = array();

      foreach ( $fields as $field ) {
        $line[] = $user->$field;
      }

      $table->addRow($line);
    }

    $table->display();

    $total = count_users();
    WP_CLI::line( 'Total: ' . $total['total_users'] . ' users' );
  }

	/**
	 * Create a user
	 *
	 * @param array $args
	 * @param array $assoc_args
	 **/
	public function users( $args, $assoc_args ) {
		global $blog_id;

		$defaults = array(
			'count' => 100,
			'role' => get_option('default_role'),
		);

		extract( wp_parse_args( $assoc_args, $defaults ), EXTR_SKIP );

		if ( 'none' == $role ) {
			$role = false;
		} elseif ( is_null( get_role( $role ) ) ) {
			WP_CLI::warning( "invalid role." );
			exit;
		}

		$user_count = count_users();

		$total = $user_count['total_users'];

		$limit = $count + $total;

		for ( $i = $total; $i < $limit; $i++ ) {
			$login = sprintf( 'user_%d_%d', $blog_id, $i );
			$name = "User $i";

			$user_id = wp_insert_user( array(
				'user_login' => $login,
				'user_pass' => <PASSWORD>,
				'nickname' => $name,
				'display_name' => $name,
				'role' => $role
			) );

			if ( false === $role ) {
				delete_user_option( $user_id, 'capabilities' );
				delete_user_option( $user_id, 'user_level' );
			}
		}
	}

	/**
	 * Help function for this command
	 */
	public static function help() {
		WP_CLI::line( <<<EOB
usage: wp generate posts [--count=100] [--type=post] [--status=publish]
   or: wp generate users [--count=100] [--role=<role>]
EOB
	);
	}
}<commit_msg>fix user count, add roles to list, add create subcommand<commit_after><?php

WP_CLI::addCommand('user', 'UserCommand');

/**
 * Implement user command
 *
 * @package wp-cli
 * @subpackage commands/internals
 */
class UserCommand extends WP_CLI_Command {
  /**
   * List users
   * 
   * @param array $args
	 * @param array $assoc_args
   **/
  public function all( $args, $assoc_args ) {
    global $blog_id;

    $table = new \cli\Table();
    $users = get_users("blog_id=$blog_id&fields=all_with_meta");
    $fields = array('ID', 'user_login', 'display_name', 'user_email',
      'user_registered');

    $table->setHeaders( array_merge($fields, array('roles')) );

    foreach ( $users as $user ) {
      $line = array();

      foreach ( $fields as $field ) {
        $line[] = $user->$field;
      }
      $line[] = implode( ',', $user->roles );

      $table->addRow($line);
    }

    $table->display();

    WP_CLI::line( 'Total: ' . count($users) . ' users' );
  }

	/**
	 * Create a user
	 *
	 * @param array $args
	 * @param array $assoc_args
	 **/
	public function create( $args, $assoc_args ) {
		global $blog_id;

    $user_login = $args[0];
    $user_email = $args[1];

    if ( ! $user_login || ! $user_email ) {
      WP_CLI::error("Login and email required (see 'wp user help').");
    }

		$defaults = array(
			'role' => get_option('default_role'),
      'user_pass' => <PASSWORD>(),
      'user_registered' => strftime( "%F %T", time() ),
		);

		extract( wp_parse_args( $assoc_args, $defaults ), EXTR_SKIP );

		if ( 'none' == $role ) {
			$role = false;
		} elseif ( is_null( get_role( $role ) ) ) {
			WP_CLI::warning( "invalid role." );
			exit;
		}

    $user_id = wp_insert_user( array(
      'user_email' => $user_email,
      'user_login' => $user_login,
      'user_pass' => <PASSWORD>,
      'user_registered' => $user_registered,
      'display_name' => $display_name,
      'role' => $role,
    ) );

    if ( is_wp_error($user_id) ) {
      WP_CLI::error( $user_id->get_error_message() );
    } else {
      if ( false === $role ) {
        delete_user_option( $user_id, 'capabilities' );
        delete_user_option( $user_id, 'user_level' );
      }
    }

    WP_CLI::line( "Created user $user_id" );
	}

	/**
	 * Help function for this command
	 */
	public static function help() {
		WP_CLI::line( <<<EOB
usage: wp user all
   or: wp user create <user_login> <user_email> [--role=<default_role>]
EOB
	);
	}
}
{'fraction_non_alphanumeric': 0.18209741114523914, 'fraction_numerical': 0.002413339183852567, 'mean_word_length': 2.9437716262975777, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 36, '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': '3859041', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1653, 'n_words': 359}