From 0d438349620988b82d21b3c0e604f6ab59c9bea0 Mon Sep 17 00:00:00 2001 From: ldoo22 Date: Tue, 2 Dec 2025 22:54:19 +0000 Subject: [PATCH 1/3] Pass command argument to abstract printer writer method calls --- lib/tty/command/printers/abstract.rb | 8 ++++---- spec/unit/printers/custom_spec.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/tty/command/printers/abstract.rb b/lib/tty/command/printers/abstract.rb index f590c3c..c977a76 100644 --- a/lib/tty/command/printers/abstract.rb +++ b/lib/tty/command/printers/abstract.rb @@ -28,19 +28,19 @@ def initialize(output, options = {}) end def print_command_start(cmd, *args) - write(cmd.to_command + "#{args.join}") + write(cmd, args.join(" ")) end def print_command_out_data(cmd, *args) - write(args.join(" ")) + write(cmd, args.join(" ")) end def print_command_err_data(cmd, *args) - write(args.join(" ")) + write(cmd, args.join(" ")) end def print_command_exit(cmd, *args) - write(args.join(" ")) + write(cmd, args.join(" ")) end def write(cmd, message) diff --git a/spec/unit/printers/custom_spec.rb b/spec/unit/printers/custom_spec.rb index a814355..990b0ee 100644 --- a/spec/unit/printers/custom_spec.rb +++ b/spec/unit/printers/custom_spec.rb @@ -5,20 +5,20 @@ before do stub_const("CustomPrinter", Class.new(TTY::Command::Printers::Abstract) do - def write(message) - output << message + def write(cmd, message) + output << "#{cmd.to_command}#{message}" end end) end it "prints command start" do printer = CustomPrinter.new(output) - cmd = TTY::Command::Cmd.new(:echo, "'hello world'") + cmd = TTY::Command::Cmd.new(:echo, "hello world") printer.print_command_start(cmd) output.rewind - expect(output.string).to eq("echo \\'hello\\ world\\'") + expect(output.string).to eq("echo hello\\ world") end it "prints command stdout data" do @@ -28,7 +28,7 @@ def write(message) printer.print_command_out_data(cmd, "data") output.rewind - expect(output.string).to eq("data") + expect(output.string).to eq("echo hello\\ worlddata") end it "prints command exit" do @@ -38,7 +38,7 @@ def write(message) printer.print_command_exit(cmd) output.rewind - expect(output.string).to be_empty + expect(output.string).to eq("echo hello\\ world") end it "accepts options" do From 4690c944251ba18859704d2b8bdb788e9f1962c9 Mon Sep 17 00:00:00 2001 From: ldoo22 Date: Tue, 2 Dec 2025 23:36:33 +0000 Subject: [PATCH 2/3] Add missing `class` to `CustomPrinter` in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 022717f..dddd821 100644 --- a/README.md +++ b/README.md @@ -607,7 +607,7 @@ Please see [lib/tty/command/printers/abstract.rb](https://github.com/piotrmurach At the very minimum you need to specify the `write` method that will be called during the lifecycle of command execution. The `write` accepts two arguments, first the currently run command instance and second the message to be printed: ```ruby -CustomPrinter < TTY::Command::Printers::Abstract +class CustomPrinter < TTY::Command::Printers::Abstract def write(cmd, message) puts cmd.to_command + message end From 50cc37e1628a48f688d8740093cf4eb3e7534933 Mon Sep 17 00:00:00 2001 From: ldoo22 Date: Tue, 2 Dec 2025 23:53:19 +0000 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3feb3e..dd46361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log +## Unreleased + +### Fixed +* Add missing `class` keyword to README example for custom printers +* Pass command argument to abstract printer writer method calls + ## [v0.10.1] - 2021-02-14 ### Fixed