From badc86e8b5b352954547af83c17e9e2af5c0d614 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Wed, 7 Dec 2022 18:47:50 +0200 Subject: [PATCH] feat: add `appendNewLine` option --- CHANGELOG.md | 4 ++++ lib/src/runnable_script.dart | 14 +++++++++++++- pubspec.yaml | 13 ++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc7756d..6264c6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2 + +- Add `appendNewLine` option (default: `false`) + ## 0.2.1 - Windows shell support (experimental) diff --git a/lib/src/runnable_script.dart b/lib/src/runnable_script.dart index 75e6422..567fc0a 100644 --- a/lib/src/runnable_script.dart +++ b/lib/src/runnable_script.dart @@ -40,8 +40,15 @@ class RunnableScript { /// When set to [true], the command will not print "Running: ...". This is useful for using the output in /// other scripts. + /// + /// Defaults to [false]. final bool suppressHeaderOutput; + /// When set to [true], the command will end with a newline. This is useful for using the output in other scripts. + /// + /// Defaults to [false]. + final bool appendNewline; + FileSystem _fileSystem; /// A runnable script with pre-defined name, cmd and args. May be run using the `run` command and optionally @@ -55,6 +62,7 @@ class RunnableScript { this.env, FileSystem? fileSystem, this.suppressHeaderOutput = false, + this.appendNewline = false, }) : _fileSystem = fileSystem ?? LocalFileSystem(); /// Generate a runnable script from a yaml loaded map as defined in the config. @@ -91,6 +99,7 @@ class RunnableScript { final cmdArgs = _utils.splitArgs(rawCmd.substring(cmd.length)); final description = map['description'] as String?; final suppressHeaderText = map['suppress_header_output'] as bool? ?? false; + final appendNewline = map['append_newline'] as bool? ?? false; // print('cmdArgs: $cmdArgs'); try { @@ -101,6 +110,7 @@ class RunnableScript { fileSystem: fileSystem, description: description, suppressHeaderOutput: suppressHeaderText, + appendNewline: appendNewline, ); } catch (e) { throw StateError( @@ -131,7 +141,9 @@ class RunnableScript { try { final exitCode = await _runShellScriptFile(config, scrPath); - print(''); + if (appendNewline) { + print(''); + } if (exitCode != 0) { final e = io.ProcessException( cmd, args, 'Process exited with error code: $exitCode', exitCode); diff --git a/pubspec.yaml b/pubspec.yaml index c66e1a4..87b1986 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.2.1 +version: 0.3.0 homepage: https://casraf.dev/ repository: https://github.com/chenasraf/dart_script_runner license: MIT @@ -13,8 +13,9 @@ dependencies: yaml: ^3.1.1 dev_dependencies: - lints: ^2.0.0 - test: ^1.16.0 + lints: + test: + btool: script_runner: # line_length: 100 @@ -24,6 +25,12 @@ script_runner: - publish: dart pub publish --force - publish:dry: dart pub publish --dry-run - doc: dart doc + - name: 'version' + cmd: dart run btool get packageVersion + suppress_header_output: true + - name: 'version:set' + cmd: dart run btool set packageVersion + suppress_header_output: true # Examples - name: echo1