From ac72b16f4a97cbb21ba7b14b04aa009ea65fcce6 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Fri, 9 Feb 2024 01:02:46 +0200 Subject: [PATCH] docs: update readme --- README.md | 20 +++++++++++++++++--- lib/src/config.dart | 31 +++++++++---------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index dd10423..0a65d84 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ in a portable, simple config. ![script_runner help output](https://github.com/chenasraf/dart_script_runner/assets/167217/d172cd98-c041-48ff-80cc-a24c80e635c7) - --- ## What for? @@ -37,20 +36,35 @@ to work similarly, though it can be customized to fit your needs more specifical You can install this package globally for the most easy usage. -```shell +```sh pub global activate script_runner ``` Once activated, you can use the supplied `scr` executable to directly call scripts from any project you are currently in. -```shell +```sh scr my-script ...args ``` You can also install this package as a dependency and build/run your own script lists. (but why would you?) +### Built-in Commands + +To get help, including the list of all scripts available in the current directory, run: + +```sh +scr -h +``` + +To list all the scripts, with the ability to search, use: + +```sh +scr -ls # see all +scr -ls terms # search for "terms" +``` + ## Usage ### Normal usage (config file) diff --git a/lib/src/config.dart b/lib/src/config.dart index b28c69f..c31fbb8 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -75,8 +75,7 @@ class ScriptRunnerConfig { final sourceMap = await _tryFindConfig(fs, startDir); if (sourceMap.isEmpty) { - throw StateError( - 'Must provide scripts in either pubspec.yaml or script_runner.yaml'); + throw StateError('Must provide scripts in either pubspec.yaml or script_runner.yaml'); } final source = sourceMap.values.first; @@ -101,9 +100,7 @@ class ScriptRunnerConfig { List? scriptsRaw, { FileSystem? fileSystem, }) { - final scripts = (scriptsRaw ?? []) - .map((script) => RunnableScript.fromMap(script, fileSystem: fileSystem)) - .toList(); + final scripts = (scriptsRaw ?? []).map((script) => RunnableScript.fromMap(script, fileSystem: fileSystem)).toList(); return scripts.map((s) => s..preloadScripts = scripts).toList(); } @@ -141,8 +138,7 @@ class ScriptRunnerConfig { (configSource?.isNotEmpty == true ? [ colorize(' on ', titleStyle), - colorize( - configSource!, [...titleStyle, TerminalColor.underline]), + colorize(configSource!, [...titleStyle, TerminalColor.underline]), colorize(':', titleStyle) ].join('') : ':'), @@ -169,15 +165,10 @@ class ScriptRunnerConfig { final filtered = search.isEmpty ? scripts - : scripts - .where((scr) => [scr.name, scr.description] - .any((s) => s != null && s.contains(search))) - .toList(); + : scripts.where((scr) => [scr.name, scr.description].any((s) => s != null && s.contains(search))).toList(); - final mapped = filtered - .map((scr) => TableRow(scr.name, - scr.description ?? '\$ ${[scr.cmd, ...scr.args].join(' ')}')) - .toList(); + final mapped = + filtered.map((scr) => TableRow(scr.name, scr.description ?? '\$ ${[scr.cmd, ...scr.args].join(' ')}')).toList(); final padLen = _getPadLen(mapped.map((r) => r.name).toList(), maxLen); @@ -189,8 +180,7 @@ class ScriptRunnerConfig { /// If [search] is provided, it filters the scripts to only those that contain the search string. void printBuiltins([String search = '']) { final builtins = [ - TableRow('-ls, --list [search]', - 'List available scripts. Add search term to filter.'), + TableRow('-ls, --list [search]', 'List available scripts. Add search term to filter.'), TableRow('-h, --help', 'Print this help message'), ]; @@ -207,8 +197,7 @@ class ScriptRunnerConfig { stripColors: true, wrapLine: (line) => colorize(line, [TerminalColor.gray]), ); - printColor(' ${scr.name.padRight(padLen, ' ')} ${lines.first}', - [TerminalColor.yellow]); + printColor(' ${scr.name.padRight(padLen, ' ')} ${lines.first}', [TerminalColor.yellow]); for (final line in lines.sublist(1)) { print(' ${''.padRight(padLen, ' ')} $line'); } @@ -216,8 +205,7 @@ class ScriptRunnerConfig { } } - static Future> _tryFindConfig( - FileSystem fs, String startDir) async { + static Future> _tryFindConfig(FileSystem fs, String startDir) async { final explorer = Unaconfig('script_runner', fs: fs); final config = await explorer.search(); if (config != null) { @@ -343,4 +331,3 @@ class TableRow { TableRow(this.name, this.description); } -