|
5 | 5 |
|
6 | 6 | require_once __DIR__ . '/../vendor/autoload.php'; |
7 | 7 |
|
8 | | - |
9 | | - |
10 | 8 | define( 'WP_SQLITE_AST_DRIVER', true ); |
11 | 9 |
|
12 | 10 | // Process CLI arguments: |
|
15 | 13 | $opts = getopt( $shortopts, $longopts ); |
16 | 14 |
|
17 | 15 | $help = <<<USAGE |
18 | | -Usage: php mysql-proxy.php --database <path/to/db.sqlite> [--port <port>] |
| 16 | +Usage: php mysql-proxy.php [--database <path/to/db.sqlite>] [--port <port>] |
19 | 17 |
|
20 | 18 | Options: |
21 | 19 | -h, --help Show this help message and exit. |
22 | | - -d, --database=<path> The path to the SQLite database file. |
23 | | - -p, --port=<port> The port to listen on. |
| 20 | + -d, --database=<path> The path to the SQLite database file. Default: :memory: |
| 21 | + -p, --port=<port> The port to listen on. Default: 3306 |
24 | 22 |
|
25 | 23 | USAGE; |
26 | 24 |
|
| 25 | +// Help. |
27 | 26 | if ( isset( $opts['h'] ) || isset( $opts['help'] ) ) { |
28 | 27 | fwrite( STDERR, $help ); |
29 | 28 | exit( 0 ); |
30 | 29 | } |
31 | 30 |
|
32 | | -$db_path = $opts['d'] ?? $opts['database'] ?? null; |
33 | | -if ( null === $db_path || '' === $db_path ) { |
34 | | - fwrite( STDERR, "Error: --database <path/to/db.sqlite> is required. Use --help for usage.\n" ); |
35 | | - exit( 1 ); |
36 | | -} |
| 31 | +// Database path. |
| 32 | +$db_path = $opts['d'] ?? $opts['database'] ?? ':memory:'; |
37 | 33 |
|
| 34 | +// Port. |
38 | 35 | $port = (int) ( $opts['p'] ?? $opts['port'] ?? 3306 ); |
39 | 36 | if ( $port < 1 || $port > 65535 ) { |
40 | | - fwrite( STDERR, "Error: --port must be an integer between 1 and 65535.\n" ); |
| 37 | + fwrite( STDERR, "Error: --port must be an integer between 1 and 65535. Use --help for more information.\n" ); |
41 | 38 | exit( 1 ); |
42 | 39 | } |
43 | 40 |
|
|
0 commit comments