public function generate($filename, $extends = NULL)
 {
     // Progress controller file
     $files = explode('/', $filename);
     $files_count = count($files);
     // Progress controller directory
     $model = array('Model');
     $directory = NULL;
     if ($files_count > 1) {
         // progress controller name
         for ($i = 0; $i < $files_count; $i++) {
             $model[] = $this->_format_name($files[$i]);
             if ($i != $files_count - 1) {
                 $directory .= $files[$i] . DIRECTORY_SEPARATOR;
             }
         }
         $filename = $files[$files_count - 1];
     } else {
         $model[] = $this->_format_name($filename);
     }
     // Set the name of controller file
     $model = implode('_', $model);
     // Set controller extends
     if ($extends) {
         $parent = strtolower($extends);
         switch ($parent) {
             case 'orm':
                 $parent = strtoupper($parent);
             default:
                 $parent = ucfirst($parent);
         }
         $extends = $parent;
     } else {
         $extends = 'Model';
     }
     // Set the name of the controller path
     $directory = $this->config->apppath . Terminal::MODELPATH . $directory;
     if (!is_dir($directory)) {
         // Create the yearly directory
         mkdir($directory, 0777, TRUE);
         // Set permissions (must be manually set to fix umask issues)
         chmod($directory, 0777);
     }
     // Set the name of the log file
     $filename = $directory . $filename . EXT;
     if (!file_exists($filename)) {
         // Create the controller file
         file_put_contents($filename, Kohana::FILE_SECURITY . PHP_EOL);
         // Allow anyone to write to controller files
         chmod($filename, 0666);
         // Continute to write
         file_put_contents($filename, PHP_EOL . 'class ' . ucfirst($model) . ' extends ' . $extends . ' {', FILE_APPEND);
         file_put_contents($filename, PHP_EOL . PHP_EOL . '}' . PHP_EOL . PHP_EOL, FILE_APPEND);
         $result = Terminal::color('create', 'green');
     } else {
         $result = Terminal::color('exist', 'blue');
     }
     $result = '    ' . $result . '  ' . Kohana::debug_path($filename);
     echo $result . PHP_EOL;
 }
 public function generate($filename)
 {
     // Progress controller file
     $files = explode('/', $filename);
     $files_count = count($files);
     // Progress controller directory
     $directory = NULL;
     if ($files_count > 1) {
         // progress controller name
         for ($i = 0; $i < $files_count; $i++) {
             if ($i != $files_count - 1) {
                 $directory .= $files[$i] . DIRECTORY_SEPARATOR;
             }
         }
         $filename = $files[$files_count - 1];
     }
     // Set the name of the controller path
     $directory = $this->config->apppath . Terminal::VIEWPATH . $directory;
     if (!is_dir($directory)) {
         // Create the yearly directory
         mkdir($directory, 0777, TRUE);
         // Set permissions (must be manually set to fix umask issues)
         chmod($directory, 0777);
     }
     // Set the name of the log file
     $filename = $directory . $filename . EXT;
     if (!file_exists($filename)) {
         // Create the controller file
         file_put_contents($filename, Kohana::FILE_SECURITY . PHP_EOL);
         // Allow anyone to write to controller files
         chmod($filename, 0666);
         $result = Terminal::color('create', 'green');
     } else {
         $result = Terminal::color('exist', 'blue');
     }
     $result = '    ' . $result . '  ' . Kohana::debug_path($filename);
     echo $result . PHP_EOL;
 }
 protected function _welcome()
 {
     $str = __('"help" was called incorrectly. Call as "./kohana help".');
     echo Terminal::color($str, 'yellow') . PHP_EOL;
 }