<commit_before><?php
/* This file is part of the XP framework's experiments
 *
 * $Id$ 
 */
  require('lang.base.php');
  xp::sapi('cli');
  uses(
    'util.log.Logger',
    'util.PropertyManager',
    'rdbms.ConnectionManager'
  );

  // {{{ main
  $params= new ParamString();
  
  // Separate runner options from class options
  $map= array();
  $options= array(
    'config'  => 'etc'
  );
  $valid= array(
    'config'  => 1,
  );
  foreach ($valid as $key => $val) {
    $valid[$key{0}]= $val;
    $map[$key{0}]= $key;
  }
  $classname= NULL;
  for ($i= 1; $i < $params->count; $i++) {
    $option= $params->list[$i];

    if (0 == strncmp($option, '--', 2)) {        // Long: --foo / --foo=bar
      $p= strpos($option, '=');
      $name= substr($option, 2, FALSE === $p ? strlen($option) : $p- 2);
      if (isset($valid[$name])) {
        if ($valid[$name] == 1) {
          $options[$name]= FALSE === $p ? NULL : substr($option, $p+ 1);
        } else {
          $options[$name]= TRUE;
        }
      }
    } else if (0 == strncmp($option, '-', 1)) {   // Short: -f / -f bar
      $short= substr($option, 1);
      if (isset($valid[$short])) {
        if ($valid[$short] == 1) {
          $options[$map[$short]]= $params->list[++$i];
        } else {
          $options[$map[$short]]= TRUE;
        }
      }
    } else {
      unset($params->list[-1]);
      $classname= $option;
      $classparams= new ParamString(array_slice($params->list, $i+ 1));
      break;
    }
  }
  
  // Sanity check
  if (!$classname) {
    Console::writeLine('*** Missing classname');
    exit(1);
  }
  
  $class= XPClass::forName($classname);
  
  // Usage
  if ($classparams->exists('help', '?')) {
    foreach ($class->getMethods() as $method) {
      if (!$method->hasAnnotation('arg')) continue;
      
      $arg= $method->getAnnotation('arg');
      $name= strtolower(preg_replace('/^set/', '', $method->getName()));;
      $comment= trim($method->getComment());
      list($first, )= $method->getArguments();
      if (isset($arg['position'])) {
        $details['#'.($arg['position'] + 1)]= $comment;
        $positional[$arg['position']]= $name;
      } else if (isset($arg['name'])) {
        $details['--'.$arg['name'].' | -'.(isset($arg['short']) ? $arg['short'] : $arg['name']{0})]= $comment;
        $extra[$arg['name']]= $first->isOptional();
      } else {
        $details['--'.$name.' | -'.(isset($arg['short']) ? $arg['short'] : $name{0})]= $comment;
        $extra[$name]= $first->isOptional();
      }
    }<commit_msg>- Beautify class not found message<commit_after><?php
/* This file is part of the XP framework's experiments
 *
 * $Id$ 
 */
  require('lang.base.php');
  xp::sapi('cli');
  uses(
    'util.log.Logger',
    'util.PropertyManager',
    'rdbms.ConnectionManager'
  );

  // {{{ main
  $params= new ParamString();
  
  // Separate runner options from class options
  $map= array();
  $options= array(
    'config'  => 'etc'
  );
  $valid= array(
    'config'  => 1,
  );
  foreach ($valid as $key => $val) {
    $valid[$key{0}]= $val;
    $map[$key{0}]= $key;
  }
  $classname= NULL;
  for ($i= 1; $i < $params->count; $i++) {
    $option= $params->list[$i];

    if (0 == strncmp($option, '--', 2)) {        // Long: --foo / --foo=bar
      $p= strpos($option, '=');
      $name= substr($option, 2, FALSE === $p ? strlen($option) : $p- 2);
      if (isset($valid[$name])) {
        if ($valid[$name] == 1) {
          $options[$name]= FALSE === $p ? NULL : substr($option, $p+ 1);
        } else {
          $options[$name]= TRUE;
        }
      }
    } else if (0 == strncmp($option, '-', 1)) {   // Short: -f / -f bar
      $short= substr($option, 1);
      if (isset($valid[$short])) {
        if ($valid[$short] == 1) {
          $options[$map[$short]]= $params->list[++$i];
        } else {
          $options[$map[$short]]= TRUE;
        }
      }
    } else {
      unset($params->list[-1]);
      $classname= $option;
      $classparams= new ParamString(array_slice($params->list, $i+ 1));
      break;
    }
  }
  
  // Sanity check
  if (!$classname) {
    Console::writeLine('*** Missing classname');
    exit(1);
  }
  try {
    $class= XPClass::forName($classname);
  } catch (ClassNotFoundException $e) {
    Console::writeLine('*** ', $e->getMessage());
    exit(1);
  }  
  
  // Usage
  if ($classparams->exists('help', '?')) {
    foreach ($class->getMethods() as $method) {
      if (!$method->hasAnnotation('arg')) continue;
      
      $arg= $method->getAnnotation('arg');
      $name= strtolower(preg_replace('/^set/', '', $method->getName()));;
      $comment= trim($method->getComment());
      list($first, )= $method->getArguments();
      if (isset($arg['position'])) {
        $details['#'.($arg['position'] + 1)]= $comment;
        $positional[$arg['position']]= $name;
      } else if (isset($arg['name'])) {
        $details['--'.$arg['name'].' | -'.(isset($arg['short']) ? $arg['short'] : $arg['name']{0})]= $comment;
        $extra[$arg['name']]= $first->isOptional();
      } else {
        $details['--'.$name.' | -'.(isset($arg['short']) ? $arg['short'] : $name{0})]= $comment;
        $extra[$name]= $first->isOptional();
      }
    }
{'fraction_non_alphanumeric': 0.24294219320145957, 'fraction_numerical': 0.007874015748031496, 'mean_word_length': 2.564681724845996, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, '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': '7575053', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1807, 'n_words': 360}