Skip to content

Commit 00c5ae4

Browse files
committed
fix: config factory
chore: remove yaml dependency
1 parent 6b32489 commit 00c5ae4

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

bin/script_runner.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import 'package:script_runner/src/utils.dart';
33

44
/// Main entrypoint for CMD script runner.
55
Future<void> main(List<String> args) async {
6+
if (args.isEmpty) {
7+
printColor('No script command provided. Use -h to see available commands.', [TerminalColor.red]);
8+
return;
9+
}
610
final scriptCmd = args.first;
711
final scriptArgs = args.sublist(1);
812
try {
913
await runScript(scriptCmd, scriptArgs);
10-
} catch (e) {
11-
printColor('$e', [TerminalColor.red]);
14+
} catch (e, stack) {
15+
printColor('$e\n$stack', [TerminalColor.red]);
1216
}
1317
}

lib/src/runnable_script.dart

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:file/local.dart';
55
import 'package:script_runner/src/config.dart';
66
// ignore: no_leading_underscores_for_library_prefixes
77
import 'package:script_runner/src/utils.dart' as _utils;
8-
import 'package:yaml/yaml.dart' as yaml;
98

109
/// A runnable script with pre-defined name, cmd and args. May be run using the `run` command and optionally
1110
/// supplying extra arguments to pass.
@@ -64,33 +63,20 @@ class RunnableScript {
6463
this.appendNewline = false,
6564
}) : _fileSystem = fileSystem ?? LocalFileSystem();
6665

67-
/// Generate a runnable script from a yaml loaded map as defined in the config.
68-
factory RunnableScript.fromYamlMap(yaml.YamlMap map,
69-
{FileSystem? fileSystem}) {
70-
final out = <String, dynamic>{};
71-
72-
if (map['name'] == null && map.keys.length == 1) {
73-
out['name'] = map.keys.first;
74-
out['cmd'] = map.values.first;
75-
} else {
76-
out.addAll(map.cast<String, dynamic>());
77-
out['args'] =
78-
(map['args'] as yaml.YamlList?)?.map((e) => e.toString()).toList();
79-
out['env'] = (map['env'] as yaml.YamlMap?)?.cast<String, String>();
80-
}
81-
try {
82-
return RunnableScript.fromMap(out, fileSystem: fileSystem);
83-
} catch (e) {
84-
throw StateError(
85-
'Failed to parse script, arguments: $map, $fileSystem. Error: $e');
86-
}
87-
}
88-
8966
/// Generate a runnable script from a normal map as defined in the config.
9067
factory RunnableScript.fromMap(
9168
Map<String, dynamic> map, {
9269
FileSystem? fileSystem,
9370
}) {
71+
if (map['name'] == null && map.keys.length == 1) {
72+
map['name'] = map.keys.first;
73+
map['cmd'] = map.values.first;
74+
} else {
75+
map.addAll(map.cast<String, dynamic>());
76+
map['args'] =
77+
(map['args'] as List?)?.map((e) => e.toString()).toList();
78+
map['env'] = (map['env'] as Map?)?.cast<String, String>();
79+
}
9480
final name = map['name'] as String;
9581
final rawCmd = map['cmd'] as String;
9682
final cmd = rawCmd;

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ dependencies:
1313
unaconfig: ^0.1.3
1414
# unaconfig:
1515
# path: ../unaconfig
16-
yaml: ^3.1.2
1716

1817
dev_dependencies:
1918
lints:

0 commit comments

Comments
 (0)