Beispiel #1
0
 public function actionExport($args)
 {
     $opt = \Gini\Util::getOpt($args, 'h', ['help', 'json', 'yaml']);
     if (isset($opt['h']) || isset($opt['help'])) {
         echo "Usage: gini config export [-h|--help] [--json|--yaml]\n";
         return;
     }
     \Gini\Config::setup();
     $items = \Gini\Config::export();
     if (isset($opt['json'])) {
         echo J($items, JSON_PRETTY_PRINT) . "\n";
     } else {
         echo yaml_emit($items, YAML_UTF8_ENCODING);
     }
 }
Beispiel #2
0
 public function actionExport($args)
 {
     $gini_bin = $_SERVER['_'];
     $opt = \Gini\Util::getOpt($args, 'hu:', ['help', 'user:'******'prefix:', 'suffix:']);
     if (isset($opt['h']) || isset($opt['help'])) {
         echo "Usage: gini cron export [-h|--help] [-u|--user=USER] [--prefix=PREFIX] [--suffix=SUFFIX]\n";
         return;
     }
     $prefix = $opt['prefix'] ?: '';
     $suffix = $opt['suffix'] ?: '';
     $user = $opt['u'] ?: $opt['user'] ?: '';
     foreach ((array) \Gini\Config::get('cron') as $cron) {
         if ($cron['comment']) {
             printf("# %s\n", $cron['comment']);
         }
         printf("%s%s\t%s%s @%s %s%s\n\n", $cron['interval'], $user ? "\t{$user}" : '', $prefix, $gini_bin, APP_ID, $cron['command'], $suffix);
     }
 }
Beispiel #3
0
 public function actionCache($args)
 {
     $opt = \Gini\Util::getOpt($args, 'he:', ['help', 'env:']);
     if (isset($opt['h']) || isset($opt['help'])) {
         echo "Usage: gini cache [-h|--help] [-e|--env=ENV] [clean]\n";
         return;
     }
     $env = $opt['e'] ?: $opt['env'] ?: null;
     if ($opt['_'][0] == 'clean') {
         \Gini\App\Cache::clean();
     } else {
         $errors = \Gini\App\Doctor::diagnose(['dependencies', 'composer']);
         if ($errors) {
             return;
         }
         \Gini\App\Cache::setup($env);
     }
 }
Beispiel #4
0
 public function actionInit($args)
 {
     $app = \Gini\Core::moduleInfo(APP_ID);
     $composer_json = ['name' => $app->id, 'description' => $app->description ?: '', 'license' => 'proprietary', 'repositories' => [['type' => 'composer', 'url' => 'http://satis.genee.cn']]];
     $opt = \Gini\Util::getOpt($args, 'n', ['no-packagist']);
     if (isset($opt['n']) || isset($opt['--no-packagist'])) {
         $composer_json['repositories'][] = ['packagist' => false];
         echo "Generating Composer configuration file without Packagist...\n";
     } else {
         echo "Generating Composer configuration file...\n";
     }
     $walked = [];
     $walk = function ($info) use(&$walk, &$walked, &$composer_json) {
         $walked[$info->id] = true;
         foreach ($info->dependencies as $name => $version) {
             if (isset($walked[$name])) {
                 continue;
             }
             $app = \Gini\Core::moduleInfo($name);
             if ($app) {
                 $walk($app);
             }
         }
         $composer_json = \Gini\Util::arrayMergeDeep($info->composer ?: [], $composer_json);
     };
     $walk($app);
     if (isset($composer_json['require']) || isset($composer_json['require-dev'])) {
         if (file_exists(APP_PATH . '/composer.json')) {
             $confirm = strtolower(readline('File exists. Overwrite? [Y/n] '));
             if ($confirm && $confirm != 'y') {
                 echo "   canceled.\n";
                 return;
             }
         }
         file_put_contents(APP_PATH . '/composer.json', J($composer_json, JSON_PRETTY_PRINT));
         echo "   done.\n";
     }
 }
Beispiel #5
0
 public function actionUpdate($args)
 {
     if (APP_ID == 'gini') {
         echo "Please run it in your App directory!\n";
         return;
     }
     $opt = \Gini\Util::getOpt($args, 'f', ['force']);
     $force = isset($opt['f']) || isset($opt['force']);
     $web_dir = APP_PATH . '/web';
     \Gini\File::ensureDir($web_dir);
     $cgi_path = realpath(dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/../lib/cgi.php');
     $index_path = $web_dir . '/index.php';
     if (file_exists($index_path) || is_link($index_path)) {
         unlink($index_path);
     }
     file_put_contents($index_path, "<?php require \"{$cgi_path}\";\n");
     $this->_merge_assets($force);
     $this->_process_css($force);
     $this->_process_js($force);
 }
Beispiel #6
0
 public function testGetOpt()
 {
     $opt = \Gini\Util::getOpt(['bar', '--prefix=hello', 'foo', '--suffix'], '', ['prefix:', 'suffix:']);
     $this->assertEquals($opt['prefix'], 'hello');
     $this->assertFalse($opt['suffix']);
 }