diff --git a/bin/script_runner.dart b/bin/script_runner.dart index 072d37b..3fbeeb4 100755 --- a/bin/script_runner.dart +++ b/bin/script_runner.dart @@ -3,11 +3,15 @@ import 'package:script_runner/src/utils.dart'; /// Main entrypoint for CMD script runner. Future main(List 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]); } } diff --git a/lib/src/runnable_script.dart b/lib/src/runnable_script.dart index 4258482..efc8008 100644 --- a/lib/src/runnable_script.dart +++ b/lib/src/runnable_script.dart @@ -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 = {}; - - if (map['name'] == null && map.keys.length == 1) { - out['name'] = map.keys.first; - out['cmd'] = map.values.first; - } else { - out.addAll(map.cast()); - out['args'] = - (map['args'] as yaml.YamlList?)?.map((e) => e.toString()).toList(); - out['env'] = (map['env'] as yaml.YamlMap?)?.cast(); - } - 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 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()); + map['args'] = + (map['args'] as List?)?.map((e) => e.toString()).toList(); + map['env'] = (map['env'] as Map?)?.cast(); + } final name = map['name'] as String; final rawCmd = map['cmd'] as String; final cmd = rawCmd; diff --git a/pubspec.yaml b/pubspec.yaml index 9c1eece..5b7d259 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,6 @@ dependencies: unaconfig: ^0.1.3 # unaconfig: # path: ../unaconfig - yaml: ^3.1.2 dev_dependencies: lints: