-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for assigning a stream to SSHKit.config.output is broken #243
Comments
I think it's just broken Rob, that was one of the earlier parts of the code that I wrote, the intention was that you set the output to anything that quacks like an IO, but apparently we've broken that somewhere along the line. I think most people drop in a heavier formatter, so I see the value in making the simple case work, but it's also a bit magic, so we could just remove that misleading line from the docs. |
OK, I will update the docs and remove support for this since it's not that straightforward to implement properly. I started adding support for a People can always pass an IO like this which isn't a huge amount of boiler-plate. SSHKit.config.output = SSHKit::Formatter::SimpleText.new(any_io) I will pick this up in a PR |
Thanks @robd I don't know what changed in your life that you have such an abundance of free time, but I'm grateful! |
No probs! My client has delayed our next project and since I have built up some understanding of SSHKit I thought I'd try and help out a bit if I can. |
:) well, the plan's working! |
## 1.8.1 * Change license to MIT, thanks to all the patient contributors who gave their permissions. ## 1.8.0 * add SSHKit::Backend::ConnectionPool#close_connections [PR #285](capistrano/sshkit#285) @akm * Clean up rubocop lint warnings [PR #275](capistrano/sshkit#275) @cshaffer * Prepend unused parameter names with an underscore * Prefer “safe assignment in condition” * Disambiguate regexp literals with parens * Prefer `sprintf` over `String#%` * No longer shadow `caller_line` variable in `DeprecationLogger` * Rescue `StandardError` instead of `Exception` * Remove useless `private` access modifier in `TestAbstract` * Disambiguate block operator with parens * Disambiguate between grouped expression and method params * Remove assertion in `TestHost#test_assert_hosts_compare_equal` that compares something with itself * Export environment variables and execute command in a subshell. [PR #273](capistrano/sshkit#273) @kuon * Introduce `log_command_start`, `log_command_data`, `log_command_exit` methods on `Formatter` [PR #257](capistrano/sshkit#257) @robd * Deprecate `@stdout` and `@stderr` accessors on `Command` * Add support for deprecation logging options. [README](README.md#deprecation-warnings), [PR #258](capistrano/sshkit#258) @robd * Quote environment variable values. [PR #250](capistrano/sshkit#250) @Sinjo - Chris Sinjakli * Simplified formatter hierarchy. [PR #248](capistrano/sshkit#248) @robd * `SimpleText` formatter now extends `Pretty`, rather than duplicating. * Hide ANSI color escape sequences when outputting to a file. [README](README.md#output-colors), [Issue #245](capistrano/sshkit#245), [PR #246](capistrano/sshkit#246) @robd * Now only color the output if it is associated with a tty, or the `SSHKIT_COLOR` environment variable is set. * Removed broken support for assigning an `IO` to the `output` config option. [Issue #243](capistrano/sshkit#243), [PR #244](capistrano/sshkit#244) @robd * Use `SSHKit.config.output = SSHKit::Formatter::SimpleText.new($stdin)` instead * Added support for `:interaction_handler` option on commands. [PR #234](capistrano/sshkit#234), [PR #242](capistrano/sshkit#242) @robd * Removed partially supported `TRACE` log level. [2aa7890](capistrano/sshkit@2aa7890) @robd * Add support for the `:strip` option to the `capture` method and strip by default on the `Local` backend. [PR #239](capistrano/sshkit#239), [PR #249](capistrano/sshkit#249) @robd * The `Local` backend now strips by default to be consistent with the `Netssh` one. * This reverses change [7d15a9a](capistrano/sshkit@7d15a9a) to the `Local` capture API to remove stripping by default. * If you require the raw, unstripped output, pass the `strip: false` option: `capture(:ls, strip: false)` * Simplified backend hierarchy. [PR #235](capistrano/sshkit#235), [PR #237](capistrano/sshkit#237) @robd * Moved duplicate implementations of `make`, `rake`, `test`, `capture`, `background` on to `Abstract` backend. * Backend implementations now only need to implement `execute_command`, `upload!` and `download!` * Removed `Printer` from backend hierarchy for `Local` and `Netssh` backends (they now just extend `Abstract`) * Removed unused `Net::SSH:LogLevelShim` * Removed dependency on the `colorize` gem. SSHKit now implements its own ANSI color logic, with no external dependencies. Note that SSHKit now only supports the `:bold` or plain modes. Other modes will be gracefully ignored. [#263](capistrano/sshkit#263) * New API for setting the formatter: `use_format`. This differs from `format=` in that it accepts options or arguments that will be passed to the formatter's constructor. The `format=` syntax will be deprecated in a future release. [#295](capistrano/sshkit#295) * SSHKit now immediately raises a `NameError` if you try to set a formatter that does not exist. [#295](capistrano/sshkit#295)
## 1.8.1 * Change license to MIT, thanks to all the patient contributors who gave their permissions. ## 1.8.0 * add SSHKit::Backend::ConnectionPool#close_connections [PR #285](capistrano/sshkit#285) @akm * Clean up rubocop lint warnings [PR #275](capistrano/sshkit#275) @cshaffer * Prepend unused parameter names with an underscore * Prefer “safe assignment in condition” * Disambiguate regexp literals with parens * Prefer `sprintf` over `String#%` * No longer shadow `caller_line` variable in `DeprecationLogger` * Rescue `StandardError` instead of `Exception` * Remove useless `private` access modifier in `TestAbstract` * Disambiguate block operator with parens * Disambiguate between grouped expression and method params * Remove assertion in `TestHost#test_assert_hosts_compare_equal` that compares something with itself * Export environment variables and execute command in a subshell. [PR #273](capistrano/sshkit#273) @kuon * Introduce `log_command_start`, `log_command_data`, `log_command_exit` methods on `Formatter` [PR #257](capistrano/sshkit#257) @robd * Deprecate `@stdout` and `@stderr` accessors on `Command` * Add support for deprecation logging options. [README](README.md#deprecation-warnings), [PR #258](capistrano/sshkit#258) @robd * Quote environment variable values. [PR #250](capistrano/sshkit#250) @Sinjo - Chris Sinjakli * Simplified formatter hierarchy. [PR #248](capistrano/sshkit#248) @robd * `SimpleText` formatter now extends `Pretty`, rather than duplicating. * Hide ANSI color escape sequences when outputting to a file. [README](README.md#output-colors), [Issue #245](capistrano/sshkit#245), [PR #246](capistrano/sshkit#246) @robd * Now only color the output if it is associated with a tty, or the `SSHKIT_COLOR` environment variable is set. * Removed broken support for assigning an `IO` to the `output` config option. [Issue #243](capistrano/sshkit#243), [PR #244](capistrano/sshkit#244) @robd * Use `SSHKit.config.output = SSHKit::Formatter::SimpleText.new($stdin)` instead * Added support for `:interaction_handler` option on commands. [PR #234](capistrano/sshkit#234), [PR #242](capistrano/sshkit#242) @robd * Removed partially supported `TRACE` log level. [2aa7890](capistrano/sshkit@2aa7890) @robd * Add support for the `:strip` option to the `capture` method and strip by default on the `Local` backend. [PR #239](capistrano/sshkit#239), [PR #249](capistrano/sshkit#249) @robd * The `Local` backend now strips by default to be consistent with the `Netssh` one. * This reverses change [7d15a9a](capistrano/sshkit@7d15a9a) to the `Local` capture API to remove stripping by default. * If you require the raw, unstripped output, pass the `strip: false` option: `capture(:ls, strip: false)` * Simplified backend hierarchy. [PR #235](capistrano/sshkit#235), [PR #237](capistrano/sshkit#237) @robd * Moved duplicate implementations of `make`, `rake`, `test`, `capture`, `background` on to `Abstract` backend. * Backend implementations now only need to implement `execute_command`, `upload!` and `download!` * Removed `Printer` from backend hierarchy for `Local` and `Netssh` backends (they now just extend `Abstract`) * Removed unused `Net::SSH:LogLevelShim` * Removed dependency on the `colorize` gem. SSHKit now implements its own ANSI color logic, with no external dependencies. Note that SSHKit now only supports the `:bold` or plain modes. Other modes will be gracefully ignored. [#263](capistrano/sshkit#263) * New API for setting the formatter: `use_format`. This differs from `format=` in that it accepts options or arguments that will be passed to the formatter's constructor. The `format=` syntax will be deprecated in a future release. [#295](capistrano/sshkit#295) * SSHKit now immediately raises a `NameError` if you try to set a formatter that does not exist. [#295](capistrano/sshkit#295)
Hey @leehambley
I wanted to discuss this before I try to fix it, but I think this syntax, which is included in the Readme, is a bit broken. Do you know, is this supposed to work, or is the readme out of date?
I rigged up a demo script with sshkit 1.7.1 to see what the output actually looks like:
The output to this looks like this:
The reason for this is a bit involved, but basically has to do with the fact that
output << cmd
is called for each stdout line, but in this caseoutput
is$stdin
rather than an implementation of theAbstract
formatter.$stdin
just callsto_s
on thecommand
each time, and theto_s
evaluates to/usr/bin/env ls -la
.Since this is broken, do you still want to keep support for this syntax? I have a PR in progress to fix this which wraps the specified output in a Formatter if it's not a
SSHKit::Formatter::Abstract
(see below), but maybe, since this is broken and no-one has complained we can just drop support for it. People can always do this:which is covered in the examples.
If we want to keep support for this, we could just format the stream with the
SimpleTextFormatter
In any case I have a PR which cleans up the tests and exposes this issue.
Cheers, Rob
The text was updated successfully, but these errors were encountered: