-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
88 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.7.5 | ||
|
||
- Feat: Command suggestions by prefix | ||
|
||
## 0.7.4 | ||
|
||
- Fix: Script ENV not being passed properly | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'config.dart'; | ||
import 'utils.dart'; | ||
|
||
/// Runs a script with the given name, and any extra arguments. | ||
/// Returns the exit code. | ||
Future<int> runScript(String entryName, List<String> args) async { | ||
final config = await ScriptRunnerConfig.get(); | ||
|
||
if (config.scripts.isEmpty) { | ||
throw ScriptStateError('No scripts found'); | ||
} | ||
|
||
if (['-h', '--help'].contains(entryName)) { | ||
config.printUsage(); | ||
return 0; | ||
} | ||
|
||
if (['-ls', '--list'].contains(entryName)) { | ||
final search = args.isNotEmpty ? args.first : ''; | ||
config.printScripts(search); | ||
return 0; | ||
} | ||
|
||
final entry = config.scriptsMap[entryName]; | ||
|
||
if (entry == null) { | ||
final suggestions = config.scriptsMap.keys | ||
.where((key) => key.toLowerCase().startsWith(entryName.toLowerCase())) | ||
.toList(); | ||
|
||
if (suggestions.isNotEmpty) { | ||
if (suggestions.length == 1) { | ||
throw ScriptStateError( | ||
'No script named "$entryName" found. Did you mean "${suggestions.single}"?', | ||
); | ||
} else { | ||
throw ScriptStateError( | ||
'No script named "$entryName" found.\n' | ||
'Did you mean one of: "${suggestions.join('", "')}"?', | ||
); | ||
} | ||
} else { | ||
throw ScriptStateError( | ||
'No script named "$entryName" found.\n' | ||
'Available scripts: ${config.scriptsMap.keys.join('", "')}', | ||
); | ||
} | ||
} | ||
|
||
return entry.run(args); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/// This is the primary library used for loading and running scripts. | ||
library script_runner; | ||
|
||
export 'src/base.dart' show runScript; | ||
export 'src/config.dart' show ScriptRunnerConfig, ScriptRunnerShellConfig; | ||
export 'src/runnable_script.dart' show RunnableScript; | ||
export 'base.dart' show runScript; | ||
export 'config.dart' show ScriptRunnerConfig, ScriptRunnerShellConfig; | ||
export 'runnable_script.dart' show RunnableScript; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters