feat: add appendNewLine option

This commit is contained in:
Chen Asraf
2022-12-07 18:47:50 +02:00
parent a3d1034244
commit badc86e8b5
3 changed files with 27 additions and 4 deletions

View File

@@ -1,3 +1,7 @@
## 0.2.2
- Add `appendNewLine` option (default: `false`)
## 0.2.1
- Windows shell support (experimental)

View File

@@ -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);

View File

@@ -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