mirror of
https://github.com/chenasraf/dart_script_runner.git
synced 2026-05-18 01:49:04 +00:00
28 lines
750 B
Dart
Executable File
28 lines
750 B
Dart
Executable File
import 'dart:io' as io;
|
|
|
|
import 'package:script_runner/base.dart';
|
|
import 'package:script_runner/utils.dart';
|
|
|
|
/// Main entrypoint for CMD script runner.
|
|
Future<void> main(List<String> args) async {
|
|
if (args.isEmpty) {
|
|
printColor('No script command provided. Use -h to see available commands.', [TerminalColor.red]);
|
|
return;
|
|
}
|
|
final scriptCmd = args.first;
|
|
final scriptArgs = args.sublist(1);
|
|
try {
|
|
final code = await runScript(scriptCmd, scriptArgs);
|
|
io.exit(code);
|
|
} catch (e, stack) {
|
|
if (e is ScriptStateError) {
|
|
printColor(e.toString(), [TerminalColor.red]);
|
|
} else {
|
|
printColor('$e\n$stack', [TerminalColor.red]);
|
|
}
|
|
if (e is io.ProcessException) {
|
|
io.exit(e.errorCode);
|
|
}
|
|
}
|
|
}
|