feat: add suppress_header_output option

This commit is contained in:
Chen Asraf
2022-09-07 01:59:19 +03:00
parent 909b50f4fb
commit 3ee3a5c3b2
4 changed files with 25 additions and 5 deletions

View File

@@ -1,3 +1,7 @@
## 0.1.9
- Add `suppress_header_output` option to allow scripts to output easily to other scripts
## 0.1.8
- Improve platform shell detection

View File

@@ -120,6 +120,9 @@ script_runner:
env:
MY_ENV: my-value
# ...
# Use to suppress the "Running: ..." output before running the command
# to make it possible to use ouput for other scripts
suppress_header_output: true
# The script to run. You can supply the args directly here, or split into
# `cmd` and `args` as a list.
cmd: my_scr 'arg1'

View File

@@ -38,6 +38,10 @@ class RunnableScript {
/// The script loader pre-loads these as temporary aliases to allow combined scripts to be run.
List<RunnableScript> preloadScripts = [];
/// When set to [true], the command will not print "Running: ...". This is useful for using the output in
/// other scripts.
final bool suppressHeaderOutput;
FileSystem _fileSystem;
/// A runnable script with pre-defined name, cmd and args. May be run using the `run` command and optionally
@@ -50,6 +54,7 @@ class RunnableScript {
this.workingDir,
this.env,
FileSystem? fileSystem,
this.suppressHeaderOutput = false,
}) : _fileSystem = fileSystem ?? LocalFileSystem();
/// Generate a runnable script from a yaml loaded map as defined in the config.
@@ -75,14 +80,17 @@ class RunnableScript {
}
/// Generate a runnable script from a normal map as defined in the config.
factory RunnableScript.fromMap(Map<String, dynamic> map,
{FileSystem? fileSystem}) {
factory RunnableScript.fromMap(
Map<String, dynamic> map, {
FileSystem? fileSystem,
}) {
final name = map['name'] as String;
final rawCmd = map['cmd'] as String;
final cmd = rawCmd.split(' ').first;
final rawArgs = (map['args'] as List<String>?) ?? [];
final cmdArgs = _utils.splitArgs(rawCmd.substring(cmd.length));
final description = map['description'] as String?;
final suppressHeaderText = map['suppress_header_output'] as bool? ?? false;
// print('cmdArgs: $cmdArgs');
try {
@@ -92,6 +100,7 @@ class RunnableScript {
args: cmdArgs + List<String>.from(rawArgs),
fileSystem: fileSystem,
description: description,
suppressHeaderOutput: suppressHeaderText,
);
} catch (e) {
throw StateError(
@@ -112,7 +121,9 @@ class RunnableScript {
final origCmd = [cmd, ...effectiveArgs.map(_utils.wrap)].join(' ');
final passCmd = '$preRun; eval \'$origCmd\'';
print('Running: $origCmd');
if (!suppressHeaderOutput) {
print('Running: $origCmd');
}
// print("Before parse $cmd $args");
try {

View File

@@ -1,6 +1,6 @@
name: script_runner
description: Run all your project-related scripts in a portable, simple config.
version: 0.1.8
version: 0.1.9
homepage: https://casraf.dev/
repository: https://github.com/chenasraf/dart_script_runner
license: MIT
@@ -21,7 +21,8 @@ script_runner:
scripts:
# Real
- auto-fix: dart fix --apply
- publish: dart pub publish
- publish: dart pub publish --force
- publish:dry: dart pub publish --dry-run
- doc: dart doc
# Examples
@@ -33,6 +34,7 @@ script_runner:
args:
- 'Hello World'
description: test script foobar
suppress_header_output: true
- name: activate-local
cmd: dart pub global activate --source path ./
- name: combined