<commit_before><?php
/**
 * actions on an individual site
 *
 */

use Terminus\Utils;
use Terminus\Auth;
use Terminus\SiteFactory;
use Terminus\Site;
use \Guzzle\Http\Client;
use \Terminus\Loggers\Regular as Logger;
use \Terminus\Helpers\Input;
use \Terminus\Deploy;
use \Terminus\SiteWorkflow;

class Site_Command extends Terminus_Command {

  public function __construct() {
    parent::__construct();
  }

  protected $_headers = false;

  /**
  * Get or set site attributes
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : site to check attributes on
  *
  * [--env=<env>]
  * : environment
  *
  * ## EXAMPLES
  *
  **/
  public function attributes($args, $assoc_args) {
    $site = SiteFactory::instance(Input::site($assoc_args));
    $data = $site->attributes();
    $this->handleDisplay($data, array(), array('Attribute','Value'));
  }

  /**
   * Create a branch for developing
   *
   * ## OPTIONS
   *
   * [--site=<site>]
   * : site to create branch of
   *
   * --branch=<branch>
   * : name of new branch
   *
   * ## EXAMPLES
   *
   * terminus branch-create --site=yoursite --branch=carebearsandunicorns
   *
   * @subcommand branch-create
  **/
  public function branch_create($args, $assoc_args) {
    $site = SiteFactory::instance(Input::site($assoc_args));
    $branch = preg_replace('#[_\s]+#',"",@$assoc_args['branch']);
    $branch = $site->createBranch($branch);
  }

  /**
   * Clear all site caches
   *
   * ## OPTIONS
   *
   * [--site=<site>]
   * : site to use
   *
   * [--env=<env>]
   * : Environment to clear
   *
   * ## EXAMPLES
   *  terminus site clear-caches --site=test
   *
   * @subcommand clear-caches
   */
  public function clear_caches($args, $assoc_args) {
      $site = SiteFactory::instance(Input::site($assoc_args));
      $env = Input::env($assoc_args, 'env');
      $response = $site->environment($env)->workflow("clear_cache");
      $this->waitOnWorkFlow('sites', $site->getId(), $response->id);
      Terminus::success("Caches cleared");
  }

  /**
   * Code related commands
   *
   * ## OPTIONS
   *
   * <log|branches|branch-create|diffstat|commit>
   * : options are log, branches, branch-create, diffstat, commit
   *
   * [--site=<site>]
   * : name of the site
   *
   * [--env=<env>]
   * : site environment
   *
   * [--message=<message>]
   * : message to use when committing on server changes
   *
   * [--branchname=<branchname>]
   * : When using branch-create specify the branchname
   */
  public function code($args, $assoc_args) {
      $subcommand = array_shift($args);
      $site = SiteFactory::instance(Input::site($assoc_args));
      $data = $headers = array();
      switch($subcommand) {
        case 'log':
          $env = Input::env($assoc_args, 'env');
          $logs = $site->environment($env)->log();
          $data = array();
          foreach ($logs as $log) {
            $data[] = array(
              'time' => $log->datetime,
              'author' => $log->author,
              'labels' => join(", ", $log->labels),
              'hash'  => $log->hash,
              'message' => trim(str_replace("\n",'',str_replace("\t",'',substr($log->message,0,50)))),
            );
          }
          break;
        case 'branches':
          $data = $site->tips();
          $headers = array('Branch','Commit');
          break;
        case 'branch-create':
          if (!isset($assoc_args['branchname'])) {
            $branch = Terminus::prompt("Name of new branch");
          } else {
            $branch = $assoc_args['branchname'];
          }
          $branch = preg_replace('#[_\s]+#',"",@$assoc_args['branchname']);
          $branch = $site->createBranch($branch);
          Terminus::success('Branch created');
          break;
        case 'commit':
          $env = Input::env($assoc_args, 'env');
          $diff = $site->environment($env)->diffstat();
          $count = count($diff);
          if (!Terminus::get_config('yes')) {
            Terminus::confirm("Commit %s changes?", $assoc_args, array($count));
          }
          $message = @$assoc_args['message'] ?: "Terminus commit.";
          $data = $site->environment($env)->onServerDev(null, $message);
          Terminus::success("Successfully commited.");
          return true;
          break;
        case 'diffstat':
          $env = Input::env($assoc_args, 'env');
          $diff = (array) $site->environment($env)->diffstat();
          if (empty($diff)) {<commit_msg>Fixed misspelling of "committed"<commit_after><?php
/**
 * actions on an individual site
 *
 */

use Terminus\Utils;
use Terminus\Auth;
use Terminus\SiteFactory;
use Terminus\Site;
use \Guzzle\Http\Client;
use \Terminus\Loggers\Regular as Logger;
use \Terminus\Helpers\Input;
use \Terminus\Deploy;
use \Terminus\SiteWorkflow;

class Site_Command extends Terminus_Command {

  public function __construct() {
    parent::__construct();
  }

  protected $_headers = false;

  /**
  * Get or set site attributes
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : site to check attributes on
  *
  * [--env=<env>]
  * : environment
  *
  * ## EXAMPLES
  *
  **/
  public function attributes($args, $assoc_args) {
    $site = SiteFactory::instance(Input::site($assoc_args));
    $data = $site->attributes();
    $this->handleDisplay($data, array(), array('Attribute','Value'));
  }

  /**
   * Create a branch for developing
   *
   * ## OPTIONS
   *
   * [--site=<site>]
   * : site to create branch of
   *
   * --branch=<branch>
   * : name of new branch
   *
   * ## EXAMPLES
   *
   * terminus branch-create --site=yoursite --branch=carebearsandunicorns
   *
   * @subcommand branch-create
  **/
  public function branch_create($args, $assoc_args) {
    $site = SiteFactory::instance(Input::site($assoc_args));
    $branch = preg_replace('#[_\s]+#',"",@$assoc_args['branch']);
    $branch = $site->createBranch($branch);
  }

  /**
   * Clear all site caches
   *
   * ## OPTIONS
   *
   * [--site=<site>]
   * : site to use
   *
   * [--env=<env>]
   * : Environment to clear
   *
   * ## EXAMPLES
   *  terminus site clear-caches --site=test
   *
   * @subcommand clear-caches
   */
  public function clear_caches($args, $assoc_args) {
      $site = SiteFactory::instance(Input::site($assoc_args));
      $env = Input::env($assoc_args, 'env');
      $response = $site->environment($env)->workflow("clear_cache");
      $this->waitOnWorkFlow('sites', $site->getId(), $response->id);
      Terminus::success("Caches cleared");
  }

  /**
   * Code related commands
   *
   * ## OPTIONS
   *
   * <log|branches|branch-create|diffstat|commit>
   * : options are log, branches, branch-create, diffstat, commit
   *
   * [--site=<site>]
   * : name of the site
   *
   * [--env=<env>]
   * : site environment
   *
   * [--message=<message>]
   * : message to use when committing on server changes
   *
   * [--branchname=<branchname>]
   * : When using branch-create specify the branchname
   */
  public function code($args, $assoc_args) {
      $subcommand = array_shift($args);
      $site = SiteFactory::instance(Input::site($assoc_args));
      $data = $headers = array();
      switch($subcommand) {
        case 'log':
          $env = Input::env($assoc_args, 'env');
          $logs = $site->environment($env)->log();
          $data = array();
          foreach ($logs as $log) {
            $data[] = array(
              'time' => $log->datetime,
              'author' => $log->author,
              'labels' => join(", ", $log->labels),
              'hash'  => $log->hash,
              'message' => trim(str_replace("\n",'',str_replace("\t",'',substr($log->message,0,50)))),
            );
          }
          break;
        case 'branches':
          $data = $site->tips();
          $headers = array('Branch','Commit');
          break;
        case 'branch-create':
          if (!isset($assoc_args['branchname'])) {
            $branch = Terminus::prompt("Name of new branch");
          } else {
            $branch = $assoc_args['branchname'];
          }
          $branch = preg_replace('#[_\s]+#',"",@$assoc_args['branchname']);
          $branch = $site->createBranch($branch);
          Terminus::success('Branch created');
          break;
        case 'commit':
          $env = Input::env($assoc_args, 'env');
          $diff = $site->environment($env)->diffstat();
          $count = count($diff);
          if (!Terminus::get_config('yes')) {
            Terminus::confirm("Commit %s changes?", $assoc_args, array($count));
          }
          $message = @$assoc_args['message'] ?: "Terminus commit.";
          $data = $site->environment($env)->onServerDev(null, $message);
          Terminus::success("Successfully committed.");
          return true;
          break;
        case 'diffstat':
          $env = Input::env($assoc_args, 'env');
          $diff = (array) $site->environment($env)->diffstat();
          if (empty($diff)) {
{'fraction_non_alphanumeric': 0.1797172986313664, 'fraction_numerical': 0.0006730984967466906, 'mean_word_length': 2.515378548895899, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 81, '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': '7209850', 'n_tokens_mistral': 2872, 'n_tokens_neox': 2861, 'n_words': 547}