README.md in process_helper-0.1.1 vs README.md in process_helper-0.1.2.pre.beta.1

- old
+ new

@@ -49,10 +49,11 @@ * [`:pseudo_terminal` (short form `:pty`)](#pseudo_terminal-short-form-pty) * [`:puts_output` (short form `:out`)](#puts_output-short-form-out) * [`:timeout` (short form `:kill`)](#timeout-short-form-kill) * [`:log_cmd` (short form `:log`)](#log_cmd-short-form-log) * [Warnings if failure output will be suppressed based on options](#warnings-if-failure-output-will-be-suppressed-based-on-options) +* [Example Helper Script](#example-helper-script) * [Version](#version) * [Contributing](#contributing) * [(Un)License](#unlicense) * [Resources](#resources) @@ -245,9 +246,34 @@ ``` > process('ls /does_not_exist', expected_exit_status: [1,2], puts_output: :never, include_output_in_exception: false) WARNING: Check your ProcessHelper options - :puts_output is :never, and :include_output_in_exception is false, so all error output will be suppressed if process fails. => "ls: /does_not_exist: No such file or directory\n" ``` + +## Example Helper Script + +You can DRY up your usage of common process helper options by making a helper script like this that you can require: + +`setup_process_helper.rb` +``` +require 'process_helper' +include ProcessHelper + +def process_without_output(cmd, options = {}) + process(cmd, {out: :error, include_output_in_exception: false}.merge(default_options_for_process_helper).merge(options)) +end + +def process_with_output(cmd, options = {}) + process(cmd, default_options_for_process_helper.merge(options)) +end + +def default_options_for_process_helper + # IMPORTANT NOTE: Running under a pseudo-terminal (pty) gives coloring and other + # benefits, but will result in end-of-line being "\r\n" instead of just "\n". + # Be aware of this if attempting to split return value into lines. + {log: true, pty: true} +end +``` ## Version You can see the version of ProcessHelper in the `ProcessHelper::VERSION` constant: