コード例 #1
0
 /**
  * Sets a configuration option
  *
  * Sets/updates config vars, creating .muse config file as needed
  *
  * @museDescription  Sets the defined key/value pair and saves it into the user's configuration
  *
  * @return  void
  **/
 public function set()
 {
     $options = $this->arguments->getOpts();
     if (empty($options)) {
         if ($this->output->isInteractive()) {
             $options = array();
             $option = $this->output->getResponse('What do you want to configure [name|email|etc...] ?');
             if (is_string($option) && !empty($option)) {
                 $options[$option] = $this->output->getResponse("What do you want your {$option} to be?");
             } else {
                 if (empty($option)) {
                     $this->output->error("Please specify what option you want to set.");
                 } else {
                     $this->output->error("The {$option} option is not currently supported.");
                 }
             }
         } else {
             $this->output = $this->output->getHelpOutput();
             $this->help();
             $this->output->render();
             return;
         }
     }
     if (Config::save($options)) {
         $this->output->addLine('Saved new configuration!', 'success');
     } else {
         $this->output->error('Failed to save configuration');
     }
 }
コード例 #2
0
 /**
  * Handle request in stack
  * 
  * @param   object  $request  Request
  * @return  mixed
  */
 public function handle(Request $request)
 {
     $response = $this->next($request);
     $arguments = $this->app['arguments'];
     $output = $this->app['output'];
     // Check for interactivity flag and set on output accordingly
     if ($arguments->getOpt('non-interactive')) {
         $output->makeNonInteractive();
     }
     // Check for color flag and set on output accordingly
     if ($arguments->getOpt('no-colors')) {
         $output->makeUnColored();
     }
     // If task is help, set the output to our output class with extra methods for rendering help doc
     if ($arguments->get('task') == 'help') {
         $output = $output->getHelpOutput();
     }
     // If the format opt is present, try to use the appropriate output subclass
     if ($arguments->getOpt('format')) {
         $output = $output->getOutputFormatter($arguments->getOpt('format'));
     }
     // Register any user specific events
     if ($hooks = Config::get('hooks')) {
         foreach ($hooks as $trigger => $scripts) {
             foreach ($scripts as $script) {
                 Event::register($trigger, function () use($script, $output) {
                     if ($output->getMode() != 'minimal') {
                         $output->addLine("Running '{$script}'");
                     }
                     shell_exec(escapeshellcmd($script));
                 });
             }
         }
     }
     // Reset the output stored on the application
     $this->app->forget('output');
     $this->app->set('output', $output);
     return $response;
 }
コード例 #3
0
 /**
  * Create a new item from scaffolding templates
  *
  * @return  void
  **/
 public function create()
 {
     $class = __NAMESPACE__ . '\\Scaffolding\\' . ucfirst($this->type);
     if (class_exists($class)) {
         $obj = new $class($this->output, $this->arguments);
     } else {
         if (empty($this->type)) {
             $this->output->error('Error: Sorry, scaffolding can\'t create nothing/everything. Try telling it what you want to create.');
         } else {
             $this->output->error('Error: Sorry, scaffolding doesn\'t know how to create a ' . $this->type);
         }
     }
     // Get author name and email - we'll go ahaed and retrieve for all create calls
     $user_name = Config::get('user_name');
     $user_email = Config::get('user_email');
     if (!$user_name || !$user_email) {
         $this->output->addSpacer()->addLine('You can specify your name and email via:')->addLine('muse configuration set --user_name="John Doe"', array('indentation' => '2', 'color' => 'blue'))->addLine('muse configuration set --user_email=john.doe@gmail.com', array('indentation' => '2', 'color' => 'blue'))->addSpacer()->error("Error: failed to retrieve author name and/or email.");
     }
     $obj->addReplacement('author_name', $user_name)->addReplacement('author_email', $user_email);
     // Call the construct method
     $obj->construct();
 }
コード例 #4
0
ファイル: Output.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Take line of text and styles and give back a formatted line.
  *
  * This will also translate textual colors and formatting words
  * to bash escape sequences.
  *
  * @param   string  $message  Raw line of text
  * @param   mixed   $styles   String or array of styles
  * @return  void
  **/
 private function formatLine(&$message, $styles)
 {
     $style = array('format' => '0', 'color' => '', 'indentation' => $this->defaultIndentation);
     // If array, parse for individual style declarations
     if (is_array($styles) && count($styles) > 0) {
         foreach ($styles as $k => $v) {
             switch ($k) {
                 case 'color':
                     $style['color'] = $this->translateColor($v);
                     break;
                 case 'format':
                     $style['format'] = $this->translateFormat($v);
                     break;
                 case 'indentation':
                     $style['indentation'] = '';
                     for ($i = 0; $i < $v; $i++) {
                         $style['indentation'] .= ' ';
                     }
                     break;
             }
         }
     } elseif (is_string($styles)) {
         switch ($styles) {
             case 'warning':
                 $style['color'] = '43';
                 break;
             case 'error':
                 $style['format'] = '1';
                 $style['color'] = '41';
                 break;
             case 'info':
                 $style['color'] = $this->translateColor('blue');
                 break;
             case 'success':
                 $style['color'] = $this->translateColor('green');
                 break;
         }
     }
     if (!Config::get('color', $this->colored)) {
         $message = $style['indentation'] . $message;
     } else {
         $messageStyles = $style['format'];
         $messageStyles .= $style['color'] ? ';' . $style['color'] : '';
         $message = chr(27) . "[" . $messageStyles . "m" . $style['indentation'] . $message . chr(27) . "[0m";
     }
 }
コード例 #5
0
 /**
  * Default (required) command
  *
  * @return  void
  **/
 public function execute()
 {
     // Note that we're using both the muse config and the global config repositories
     $this->output->addLine('Current user     : '******'user_name') . ' <' . Config::get('user_email') . '>');
     $this->output->addLine('Current database : ' . \Config::get('db'));
 }
コード例 #6
0
ファイル: Arguments.php プロジェクト: mined-gatech/framework
 /**
  * Routes task to the proper method based on the input given
  *
  * @param   string  $command  The command to route
  * @param   string  $class    The class deduced from routeCommand
  * @param   string  $task     The task to route
  * @return  void
  **/
 public static function routeTask($command, $class, $task = 'execute')
 {
     // Aliases take precedence, so parse for them first
     if ($aliases = Config::get('aliases')) {
         if (array_key_exists($command, $aliases)) {
             if (strpos($aliases->{$command}, '::') !== false) {
                 $bits = explode('::', $aliases->{$command});
                 $task = $bits[1];
             }
         }
     }
     // Make sure task exists
     if (!method_exists($class, $task)) {
         throw new UnsupportedTaskException("{$class} does not support the {$task} method.");
     }
     return $task;
 }
コード例 #7
0
ファイル: Repository.php プロジェクト: mined-gatech/framework
 /**
  * Run syntax checker on changed files
  *
  * @museDescription  Verifies the validity of the syntax of any pending changes
  *
  * @return  void
  **/
 public function syntax()
 {
     // Get files
     $status = $this->mechanism->status();
     $files = isset($status['added']) || isset($status['modified']) ? array_merge($status['added'], $status['modified']) : array();
     // Whether or not to scan untracked files
     if (!$this->arguments->getOpt('exclude-untracked')) {
         $files = isset($status['untracked']) ? array_merge($files, $status['untracked']) : $files;
     }
     // Did we find any files?
     if ($files && count($files) > 0) {
         // Base standards directory
         if (!($standards = Config::get('repository_standards_dir'))) {
             $this->output->addSpacer()->addLine('You must specify your standards directory first via:')->addLine('muse configuration set --repository_standards_dir=/path/to/standards', array('indentation' => '2', 'color' => 'blue'))->addSpacer()->error("Error: failed to retrieve standards directory.");
         } else {
             $standards = rtrim($standards, DS) . DS . 'HubzeroCS';
         }
         // See what branch we're on, and set standards directory accordingly
         $branch = $this->mechanism->getMechanismVersionName();
         $branch = str_replace('.', '', $branch);
         if (!is_dir($standards . $branch)) {
             $this->output->error('A standards directory for the current branch does not exist');
         }
         if ($this->arguments->getOpt('no-linting') && $this->arguments->getOpt('no-sniffing')) {
             $this->output->addLine('No sniffing or linting...that means we\'re not doing anything!', 'warning');
         }
         foreach ($files as $file) {
             $this->output->addString("Scanning {$file}...");
             $passed = true;
             $base = $this->mechanism->getBasePath();
             $base = rtrim($base, DS) . DS;
             // Lint files with php extension
             if (!$this->arguments->getOpt('no-linting')) {
                 if (substr($file, -4) == '.php') {
                     $cmd = "php -l {$base}{$file}";
                     exec($cmd, $output, $code);
                     if ($code !== 0) {
                         $passed = false;
                         $this->output->addLine("failed php linter", array('color' => 'red'));
                     }
                 }
             }
             // Now run them through PHP code sniffer
             if (!$this->arguments->getOpt('no-sniffing')) {
                 // Append specific standard (with branchname) to command
                 $cmd = "php " . PATH_CORE . DS . 'bin' . DS . "phpcs --standard={$standards}{$branch}/ruleset.xml -n {$base}{$file}";
                 $cmd = escapeshellcmd($cmd);
                 $result = shell_exec($cmd);
                 if (!empty($result)) {
                     $passed = false;
                     $this->output->addLine($result, array('color' => 'red'));
                 }
             }
             // Did it all pass?
             if ($passed) {
                 $this->output->addLine('clear');
             }
         }
     } else {
         $this->output->addLine('No files to scan');
     }
 }
コード例 #8
0
 /**
  * Initialise the application
  *
  * @param  array $options an optional associative array of configuration settings.
  * @return void
  */
 public function initialise($options = [])
 {
     $arguments = App::get('arguments');
     $output = App::get('output');
     try {
         $arguments->parse();
     } catch (UnsupportedCommandException $e) {
         $output->error($e->getMessage());
     } catch (UnsupportedTaskException $e) {
         $output->error($e->getMessage());
     }
     // Check for interactivity flag and set on output accordingly
     if ($arguments->getOpt('non-interactive')) {
         $output->makeNonInteractive();
     }
     // Check for color flag and set on output accordingly
     if ($arguments->getOpt('no-colors')) {
         $output->makeUnColored();
     }
     // If task is help, set the output to our output class with extra methods for rendering help doc
     if ($arguments->get('task') == 'help') {
         $output = $output->getHelpOutput();
     }
     // If the format opt is present, try to use the appropriate output subclass
     if ($arguments->getOpt('format')) {
         $output = $output->getOutputFormatter($arguments->getOpt('format'));
     }
     // Register any user specific events
     if ($hooks = Config::get('hooks')) {
         foreach ($hooks as $trigger => $scripts) {
             foreach ($scripts as $script) {
                 Event::register($trigger, function () use($script, $output) {
                     if ($output->getMode() != 'minimal') {
                         $output->addLine("Running '{$script}'");
                     }
                     shell_exec(escapeshellcmd($script));
                 });
             }
         }
     }
     // Reset the output stored on the application
     App::forget('output');
     App::set('output', $output);
 }