Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add help messages to the cli and clarify some options #27

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ Steam OpenId support is required on your local server. Enable it with [screepsmo

All of the command line arguments are optional.

- `--package` — Used to set the path to the Screeps package.nw file. Use this if the path isn't automatically detected.
- `--package` — Path to the Screeps package.nw file. Use this if the path isn't automatically detected.
- `--host` — Changes the host address. (default: localhost)
- `--port` — Changes the port. (default: 8080)
- `--backend` — Used to configure a backend url. If provided, the client app proxies this endpoint and the server list page is disabled.
- `--internal_backend` — Used to configure an internal backend url. If provided, the client app uses this address to reference the internal server endpoint.
- `--server_list` — Used to set the path to a custom server list json config file.
- `--backend` — Set the backend url. When provided, the app will directly proxy this server and disable the server list page.
- `--internal_backend` — Set the backend's internal url. Requires --backend to be set. When provided, the app will use this url to connect to the server while still using its --backend name externally.
- `--server_list` — Path to a custom server list json config file.
- `--beautify` — Formats .js files loaded in the client for debugging.
- `--debug` — Display verbose errors for development.
- `-v` , `--version` — Display the version number.
Expand Down
58 changes: 47 additions & 11 deletions src/clientApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,55 @@ const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
const version = packageJson.version || '1.0.0';
const arrow = '\u2192';

const DEFAULT_HOST = 'localhost';
const DEFAULT_PORT = 8080;

// Parse program arguments
const argv = (() => {
const parser = new ArgumentParser();
const parser = new ArgumentParser({ description: 'Web proxy for the Screeps World game client.' });
parser.add_argument('-v', '--version', { action: 'version', version: `v${version}` });
parser.add_argument('--package', { nargs: '?', type: 'str' });
parser.add_argument('--host', { nargs: '?', type: 'str' });
parser.add_argument('--port', { nargs: '?', type: 'int' });
parser.add_argument('--backend', { nargs: '?', type: 'str' });
parser.add_argument('--internal_backend', { nargs: '?', type: 'str' });
parser.add_argument('--server_list', { nargs: '?', type: 'str' });
parser.add_argument('--beautify', { action: 'store_true', default: false });
parser.add_argument('--debug', { action: 'store_true', default: false });
parser.add_argument('--package', {
nargs: '?',
type: 'str',
help: "Path to the Screeps package.nw file. Use this if the path isn't automatically detected.",
});
parser.add_argument('--host', {
nargs: '?',
type: 'str',
default: DEFAULT_HOST,
help: `Changes the host address. (default: ${DEFAULT_HOST})`,
});
parser.add_argument('--port', {
nargs: '?',
type: 'int',
default: DEFAULT_PORT,
help: `Changes the port. (default: ${DEFAULT_PORT})`,
});
parser.add_argument('--backend', {
nargs: '?',
type: 'str',
help: 'Set the backend url. When provided, the app will directly proxy this server and disable the server list page.',
});
parser.add_argument('--internal_backend', {
nargs: '?',
type: 'str',
help: "Set the backend's internal url. Requires --backend to be set. When provided, the app will use this url to connect to the server while still using its --backend name externally.",
});
parser.add_argument('--server_list', {
nargs: '?',
type: 'str',
help: 'Path to a custom server list json config file.',
});
parser.add_argument('--beautify', {
action: 'store_true',
default: false,
help: 'Formats .js files loaded in the client for debugging.',
});
parser.add_argument('--debug', {
action: 'store_true',
default: false,
help: 'Display verbose errors for development.',
});
return parser.parse_args();
})();

Expand Down Expand Up @@ -88,8 +125,7 @@ const lastModified = stat.mtime;

// Set up web server
const koa = new Koa();
const port = argv.port ?? 8080;
const host = argv.host ?? 'localhost';
const { host, port } = argv;
const server = koa.listen(port, host);
server.on('error', (err) => handleServerError(err, argv.debug));
server.on('listening', () => console.log('🌐', chalk.dim('Ready', arrow), chalk.white(`http://${host}:${port}/`)));
Expand Down
Loading