Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
chenasraf committed Feb 8, 2024
1 parent b64cae9 commit ac72b16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 9 additions & 22 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -101,9 +100,7 @@ class ScriptRunnerConfig {
List<dynamic>? 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();
}

Expand Down Expand Up @@ -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('')
: ':'),
Expand All @@ -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);

Expand All @@ -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'),
];

Expand All @@ -207,17 +197,15 @@ 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');
}
print('');
}
}

static Future<Map<String, Map>> _tryFindConfig(
FileSystem fs, String startDir) async {
static Future<Map<String, Map>> _tryFindConfig(FileSystem fs, String startDir) async {
final explorer = Unaconfig('script_runner', fs: fs);
final config = await explorer.search();
if (config != null) {
Expand Down Expand Up @@ -343,4 +331,3 @@ class TableRow {

TableRow(this.name, this.description);
}

0 comments on commit ac72b16

Please sign in to comment.