-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole
executable file
·56 lines (45 loc) · 1.75 KB
/
console
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
#!/usr/bin/env php
<?php
declare(strict_types=1);
namespace Timesplinter\Oyster\Bin;
use Timesplinter\Oyster\Command\CdCommand;
use Timesplinter\Oyster\Command\HistoryCommand;
use Timesplinter\Oyster\Console;
use Timesplinter\Oyster\Executor;
use Timesplinter\Oyster\Command\PwdCommand;
use Timesplinter\Oyster\Helper\NullHistory;
use Timesplinter\Oyster\History\ReadlineHistory;
use Timesplinter\Oyster\Input\ReadlineInput;
use Timesplinter\Oyster\Input\StdInInput;
use Timesplinter\Oyster\OperatingSystemAdapter\DarwinAdapter;
use Timesplinter\Oyster\OperatingSystemAdapter\LinuxAdapter;
use Timesplinter\Oyster\Output\BufferedOutput;
use Timesplinter\Oyster\Output\StdOutOutput;
require __DIR__ . '/vendor/autoload.php';
$stdOutOutput = new StdOutOutput();
$osAdapterOutput = new BufferedOutput();
$osAdapterExecutor = new Executor($osAdapterOutput, Executor::MODE_PIPE);
if ('Darwin' === PHP_OS) {
$osAdapter = new DarwinAdapter($osAdapterExecutor, $osAdapterOutput);
} elseif ('Linux' === PHP_OS) {
$osAdapter = new LinuxAdapter($osAdapterExecutor, $osAdapterOutput);
} else {
$stdOutOutput->writeLn('Operating system currently not supported: '.PHP_OS);
exit;
}
if(true === function_exists('readline')) {
$history = new ReadlineHistory();
$input = new ReadlineInput();
} else {
$history = new NullHistory();
$input = new StdInInput();
$stdOutOutput->writeLn('INFO: You\'re PHP binary isn\'t compiled with readline support.');
}
$builtinCommands = [
new PwdCommand($stdOutOutput),
new CdCommand($osAdapter),
new HistoryCommand($stdOutOutput, $history),
];
$executor = new Executor($stdOutOutput, Executor::MODE_TTY);
$console = new Console($input, $stdOutOutput, $osAdapter, $builtinCommands, $executor, $history);
$console->run();