| OLD | NEW |
| (Empty) |
| 1 | |
| 2 library which.src.which_impl; | |
| 3 | |
| 4 import 'dart:async'; | |
| 5 | |
| 6 import 'package:when/when.dart'; | |
| 7 | |
| 8 import 'util.dart'; | |
| 9 | |
| 10 Future<String> which( | |
| 11 String command, | |
| 12 Iterable<String> candidatePaths, | |
| 13 bool isWindows, | |
| 14 Future<bool> isExecutable(String path, bool isWindows), | |
| 15 orElse()) => new Future(() => _which( | |
| 16 command, | |
| 17 candidatePaths, | |
| 18 isWindows, | |
| 19 isExecutable, | |
| 20 orElse, | |
| 21 toSequence: (items) => new Stream.fromIterable(items))); | |
| 22 | |
| 23 String whichSync( | |
| 24 String command, | |
| 25 Iterable<String> candidatePaths, | |
| 26 bool isWindows, | |
| 27 bool isExecutable(String path, bool isWindows), | |
| 28 orElse()) => _which( | |
| 29 command, | |
| 30 candidatePaths, | |
| 31 isWindows, | |
| 32 isExecutable, | |
| 33 orElse); | |
| 34 | |
| 35 _which( | |
| 36 String command, | |
| 37 Iterable<String> candidatePaths, | |
| 38 bool isWindows, | |
| 39 isExecutable(String path, bool isWindows), | |
| 40 orElse(), | |
| 41 {toSequence(Iterable items): identity}) => when( | |
| 42 () => firstWhere( | |
| 43 toSequence(candidatePaths), | |
| 44 (path) => isExecutable(path, isWindows), | |
| 45 orElse: orElse != null ? orElse : () => _commandNotFound(command, null))
, | |
| 46 onError: (e) => _commandNotFound(command, e)); | |
| 47 | |
| 48 _commandNotFound(String command, e) { | |
| 49 var message = 'Command not found: $command'; | |
| 50 if (e != null) message += '\n$e'; | |
| 51 throw new StateError(message); | |
| 52 } | |
| OLD | NEW |