platform/packages/production/lib/src/options.dart

73 lines
2.8 KiB
Dart
Raw Normal View History

2018-09-04 20:04:53 +00:00
import 'dart:io';
import 'package:args/args.dart';
2021-07-18 06:02:25 +00:00
/// Options for executing Runner.
2018-09-04 20:04:53 +00:00
class RunnerOptions {
2021-07-18 06:02:25 +00:00
/// Command line arguements
2019-04-28 17:51:08 +00:00
static final ArgParser argParser = ArgParser()
2018-09-04 20:04:53 +00:00
..addFlag('help',
abbr: 'h', help: 'Print this help information.', negatable: false)
..addFlag('respawn',
help: 'Automatically respawn crashed application instances.',
defaultsTo: true,
negatable: true)
..addFlag('use-zone',
negatable: false, help: 'Create a new Zone for each request.')
2019-04-28 17:51:08 +00:00
..addFlag('quiet', negatable: false, help: 'Completely mute logging.')
..addFlag('ssl',
negatable: false, help: 'Listen for HTTPS instead of HTTP.')
..addFlag('http2',
negatable: false, help: 'Listen for HTTP/2 instead of HTTP/1.1.')
2018-09-04 20:04:53 +00:00
..addOption('address',
abbr: 'a', defaultsTo: '127.0.0.1', help: 'The address to listen on.')
..addOption('concurrency',
abbr: 'j',
defaultsTo: Platform.numberOfProcessors.toString(),
help: 'The number of isolates to spawn.')
..addOption('port',
2019-04-28 17:51:08 +00:00
abbr: 'p', defaultsTo: '3000', help: 'The port to listen on.')
..addOption('certificate-file', help: 'The PEM certificate file to read.')
..addOption('certificate-password',
help: 'The PEM certificate file password.')
..addOption('key-file', help: 'The PEM key file to read.')
..addOption('key-password', help: 'The PEM key file password.');
2018-09-04 20:04:53 +00:00
2023-11-13 00:59:18 +00:00
final String hostname;
final String? certificateFile, keyFile, certificatePassword, keyPassword;
2018-09-04 20:04:53 +00:00
final int concurrency, port;
2021-07-18 05:49:37 +00:00
final bool useZone, respawn, quiet, ssl, http2;
2023-11-13 00:59:18 +00:00
final Map<String, Object> removeResponseHeaders = {};
final Map<String, Object> responseHeaders = {};
2018-09-04 20:04:53 +00:00
RunnerOptions(
2019-04-28 17:09:44 +00:00
{this.hostname = '127.0.0.1',
this.port = 3000,
this.concurrency = 1,
this.useZone = false,
2019-04-28 17:51:08 +00:00
this.respawn = true,
this.quiet = false,
this.certificateFile,
this.keyFile,
this.ssl = false,
this.http2 = false,
this.certificatePassword,
this.keyPassword});
2018-09-04 20:04:53 +00:00
factory RunnerOptions.fromArgResults(ArgResults argResults) {
2019-04-28 17:51:08 +00:00
return RunnerOptions(
2023-11-13 00:59:18 +00:00
hostname: argResults['address'] as String,
2018-09-04 20:04:53 +00:00
port: int.parse(argResults['port'] as String),
concurrency: int.parse(argResults['concurrency'] as String),
2021-07-18 05:49:37 +00:00
useZone: argResults['use-zone'] as bool? ?? false,
respawn: argResults['respawn'] as bool? ?? true,
quiet: argResults['quiet'] as bool? ?? false,
2023-11-13 00:59:18 +00:00
certificateFile: argResults['certificate-file'] as String?,
keyFile: argResults['key-file'] as String?,
2021-07-18 05:49:37 +00:00
ssl: argResults['ssl'] as bool? ?? false,
http2: argResults['http2'] as bool? ?? false,
2023-11-13 00:59:18 +00:00
certificatePassword: argResults['certificate-password'] as String?,
keyPassword: argResults['key-password'] as String?,
2018-09-04 20:04:53 +00:00
);
}
}