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

80 lines
2.9 KiB
Dart
Raw Normal View History

2018-09-04 20:04:53 +00:00
import 'dart:io';
import 'package:args/args.dart';
class RunnerOptions {
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
2019-04-28 17:51:08 +00:00
final String hostname,
certificateFile,
keyFile,
certificatePassword,
keyPassword;
2018-09-04 20:04:53 +00:00
final int concurrency, port;
2019-04-28 17:51:08 +00:00
final bool useZone, respawn, quiet, ssl, http2;
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(
2018-09-04 20:04:53 +00:00
hostname: argResults['address'] as String,
port: int.parse(argResults['port'] as String),
concurrency: int.parse(argResults['concurrency'] as String),
useZone: argResults['use-zone'] as bool,
respawn: argResults['respawn'] as bool,
2019-04-28 17:51:08 +00:00
quiet: argResults['quiet'] as bool,
certificateFile: argResults.wasParsed('certificate-file')
? argResults['certificate-file'] as String
: null,
keyFile: argResults.wasParsed('key-file')
? argResults['key-file'] as String
: null,
ssl: argResults['ssl'] as bool,
http2: argResults['http2'] as bool,
certificatePassword: argResults.wasParsed('certificate-password')
? argResults['certificate-password'] as String
: null,
keyPassword: argResults.wasParsed('key-password')
? argResults['key-password'] as String
: null,
2018-09-04 20:04:53 +00:00
);
}
}