Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php

/* vim: set shiftwidth=2 expandtab softtabstop=2: */

namespace Boris;

/**
 * Processes available command line flags.
 */
class CLIOptionsHandler {
  /**
   * Accept the REPL object and perform any setup necessary from the CLI flags.
   *
   * @param Boris $boris
   */
  public function handle($boris) {
    $args = getopt('hvr:', array('help', 'version', 'require:'));

    foreach ($args as $option => $value) {
      switch ($option) {
        /*
         * Sets files to load at startup, may be used multiple times,
         * i.e: boris -r test.php,foo/bar.php -r ba/foo.php --require hey.php
         */
        case 'r':
        case 'require':
          $this->_handleRequire($boris, $value);
        break;

        /*
         * Show Usage info
         */
        case 'h':
        case 'help':
          $this->_handleUsageInfo();
        break;

        /*
         * Show version
         */
        case 'v':
        case 'version':
          $this->_handleVersion();
        break;
      }
    }
  }

  // -- Private Methods

  private function _handleRequire($boris, $paths) {
    $require = array_reduce(
      (array) $paths,
      function($acc, $v) { return array_merge($acc, explode(',', $v)); },
      array()
    );

    $boris->onStart(function($worker, $scope) use($require) {
      foreach($require as $path) {
        require $path;
      }

      $worker->setLocal(get_defined_vars());
    });
  }

  private function _handleUsageInfo() {
    echo <<<USAGE
Usage: boris [options]
boris is a tiny REPL for PHP

Options:
  -h, --help     show this help message and exit
  -r, --require  a comma-separated list of files to require on startup
  -v, --version  show Boris version

USAGE;
    exit(0);
  }

  private function _handleVersion() {
    printf("Boris %s\n", Boris::VERSION);
    exit(0);
  }
}

Commits for Nextrek/Aiba_backup/vendor/d11wtq/boris/lib/Boris/CLIOptionsHandler.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000