mirror of
https://github.com/chenasraf/dart_script_runner.git
synced 2026-05-17 17:48:03 +00:00
fix: config factory
chore: remove yaml dependency
This commit is contained in:
@@ -3,11 +3,15 @@ import 'package:script_runner/src/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 {
|
||||
await runScript(scriptCmd, scriptArgs);
|
||||
} catch (e) {
|
||||
printColor('$e', [TerminalColor.red]);
|
||||
} catch (e, stack) {
|
||||
printColor('$e\n$stack', [TerminalColor.red]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:file/local.dart';
|
||||
import 'package:script_runner/src/config.dart';
|
||||
// ignore: no_leading_underscores_for_library_prefixes
|
||||
import 'package:script_runner/src/utils.dart' as _utils;
|
||||
import 'package:yaml/yaml.dart' as yaml;
|
||||
|
||||
/// A runnable script with pre-defined name, cmd and args. May be run using the `run` command and optionally
|
||||
/// supplying extra arguments to pass.
|
||||
@@ -64,33 +63,20 @@ class RunnableScript {
|
||||
this.appendNewline = false,
|
||||
}) : _fileSystem = fileSystem ?? LocalFileSystem();
|
||||
|
||||
/// Generate a runnable script from a yaml loaded map as defined in the config.
|
||||
factory RunnableScript.fromYamlMap(yaml.YamlMap map,
|
||||
{FileSystem? fileSystem}) {
|
||||
final out = <String, dynamic>{};
|
||||
|
||||
if (map['name'] == null && map.keys.length == 1) {
|
||||
out['name'] = map.keys.first;
|
||||
out['cmd'] = map.values.first;
|
||||
} else {
|
||||
out.addAll(map.cast<String, dynamic>());
|
||||
out['args'] =
|
||||
(map['args'] as yaml.YamlList?)?.map((e) => e.toString()).toList();
|
||||
out['env'] = (map['env'] as yaml.YamlMap?)?.cast<String, String>();
|
||||
}
|
||||
try {
|
||||
return RunnableScript.fromMap(out, fileSystem: fileSystem);
|
||||
} catch (e) {
|
||||
throw StateError(
|
||||
'Failed to parse script, arguments: $map, $fileSystem. Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a runnable script from a normal map as defined in the config.
|
||||
factory RunnableScript.fromMap(
|
||||
Map<String, dynamic> map, {
|
||||
FileSystem? fileSystem,
|
||||
}) {
|
||||
if (map['name'] == null && map.keys.length == 1) {
|
||||
map['name'] = map.keys.first;
|
||||
map['cmd'] = map.values.first;
|
||||
} else {
|
||||
map.addAll(map.cast<String, dynamic>());
|
||||
map['args'] =
|
||||
(map['args'] as List?)?.map((e) => e.toString()).toList();
|
||||
map['env'] = (map['env'] as Map?)?.cast<String, String>();
|
||||
}
|
||||
final name = map['name'] as String;
|
||||
final rawCmd = map['cmd'] as String;
|
||||
final cmd = rawCmd;
|
||||
|
||||
@@ -13,7 +13,6 @@ dependencies:
|
||||
unaconfig: ^0.1.3
|
||||
# unaconfig:
|
||||
# path: ../unaconfig
|
||||
yaml: ^3.1.2
|
||||
|
||||
dev_dependencies:
|
||||
lints:
|
||||
|
||||
Reference in New Issue
Block a user