diff --git a/CHANGELOG.md b/CHANGELOG.md index f33eb0a..7fcf334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 248b488..e4a83ad 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/lib/src/runnable_script.dart b/lib/src/runnable_script.dart index 85ff92b..b711766 100644 --- a/lib/src/runnable_script.dart +++ b/lib/src/runnable_script.dart @@ -38,6 +38,10 @@ class RunnableScript { /// The script loader pre-loads these as temporary aliases to allow combined scripts to be run. List 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 map, - {FileSystem? fileSystem}) { + factory RunnableScript.fromMap( + Map 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?) ?? []; 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.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 { diff --git a/pubspec.yaml b/pubspec.yaml index 78a9354..6457477 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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