run method
Runs Clarc with arguments and returns a process-friendly exit code.
The return value follows the executable behavior:
0for success or help output.1for validation errors, cancelled commands, and runtime failures.64for command usage or argument parser errors.
Implementation
Future<int> run(List<String> arguments) async {
final parser = _buildParser();
try {
final results = parser.parse(arguments);
if (results['help'] as bool || arguments.isEmpty) {
_printHelp(parser);
return _ExitCode.success;
}
final command = results.command;
if (command?.name != 'create') {
_printHelp(parser);
return _ExitCode.usage;
}
if (command!['help'] as bool) {
_printCreateHelp();
return _ExitCode.success;
}
final subCommand = command.command;
switch (subCommand?.name) {
case 'project':
if (subCommand!['help'] as bool) {
_printProjectHelp();
return _ExitCode.success;
}
await _createProject(subCommand);
case 'module':
if (subCommand!['help'] as bool) {
_printModuleHelp();
return _ExitCode.success;
}
await _createModule(subCommand);
case 'page':
if (subCommand!['help'] as bool) {
_printPageHelp();
return _ExitCode.success;
}
await _createPage(subCommand);
default:
_printCreateHelp();
return _ExitCode.usage;
}
return _ExitCode.success;
} on ArgParserException catch (error) {
_logger.err(error.message);
_printHelp(parser);
return _ExitCode.usage;
} on FormatException catch (error) {
_logger.err(error.message);
return _ExitCode.failure;
} on CliCancelledException catch (error) {
_logger.warn(error.message);
return _ExitCode.failure;
} on CliException catch (error) {
_logger.err(error.message);
return _ExitCode.failure;
}
}