buildServiceRunner function
Assembles the dart-service CommandRunner.
managerFactory supplies the DartServiceManager each command runs
against; the default builds one wired for the current platform, while tests
inject a manager backed by fakes. out receives all human-readable output.
Implementation
CommandRunner<int> buildServiceRunner({
ManagerFactory? managerFactory,
StringSink? out,
}) {
final sink = out ?? stdout;
final factory = managerFactory ?? _defaultManagerFactory;
final runner =
CommandRunner<int>(
'dart-service',
'Declare, compile, install and manage Dart-package services as '
'native OS services.',
)
..argParser.addOption(
'scope',
allowed: ['user', 'system'],
defaultsTo: 'user',
help: 'Privilege scope to install services under.',
)
..argParser.addFlag(
'system',
negatable: false,
help:
'Shorthand for --scope system (install a machine-wide service; '
'requires root/Administrator).',
)
..argParser.addOption(
'path',
help:
'Explicit path to the package directory (overrides name '
'resolution).',
)
..argParser.addFlag(
'verbose',
abbr: 'v',
negatable: false,
help: 'Enable debug logging.',
);
for (final command in [
InstallCommand(factory, sink),
UninstallCommand(factory, sink),
StartCommand(factory, sink),
StopCommand(factory, sink),
PauseCommand(factory, sink),
ResumeCommand(factory, sink),
RestartCommand(factory, sink),
StatusCommand(factory, sink),
ListCommand(factory, sink),
PackagesCommand(factory, sink),
ServicesCommand(factory, sink),
]) {
runner.addCommand(command);
}
return runner;
}