File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 1+ import 'dart:io' as io;
2+
13import 'package:script_runner/src/base.dart' ;
24import 'package:script_runner/src/utils.dart' ;
35
@@ -10,8 +12,12 @@ Future<void> main(List<String> args) async {
1012 final scriptCmd = args.first;
1113 final scriptArgs = args.sublist (1 );
1214 try {
13- await runScript (scriptCmd, scriptArgs);
15+ final code = await runScript (scriptCmd, scriptArgs);
16+ io.exit (code);
1417 } catch (e, stack) {
1518 printColor ('$e \n $stack ' , [TerminalColor .red]);
19+ if (e is io.ProcessException ) {
20+ io.exit (e.errorCode);
21+ }
1622 }
1723}
Original file line number Diff line number Diff line change 11import 'package:script_runner/src/config.dart' ;
22
33/// Runs a script with the given name, and any extra arguments.
4- Future <void > runScript (String entryName, List <String > args) async {
4+ /// Returns the exit code.
5+ Future <int > runScript (String entryName, List <String > args) async {
56 final config = await ScriptRunnerConfig .get ();
67 if (config.scripts.isEmpty) {
78 throw StateError ('No scripts found' );
89 }
910 if (['-h' , '--help' ].contains (entryName)) {
1011 config.printUsage ();
11- return ;
12+ return 0 ;
1213 }
1314 if (['-ls' , '--list' ].contains (entryName)) {
1415 final search = args.isNotEmpty ? args.first : '' ;
1516 config.printScripts (search);
16- return ;
17+ return 0 ;
1718 }
1819 final entry = config.scriptsMap[entryName];
1920 if (entry == null ) {
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ class RunnableScript {
101101 }
102102
103103 /// Runs the current script with the given extra arguments.
104- Future <dynamic > run (List <String > extraArgs) async {
104+ Future <int > run (List <String > extraArgs) async {
105105 final effectiveArgs = args + extraArgs;
106106 final config = await ScriptRunnerConfig .get (_fileSystem);
107107
@@ -135,6 +135,7 @@ class RunnableScript {
135135 );
136136 throw e;
137137 }
138+ return exitCode;
138139 } finally {
139140 await _fileSystem.file (scrPath).delete ();
140141 }
You can’t perform that action at this time.
0 commit comments