-
Notifications
You must be signed in to change notification settings - Fork 253
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
Add strip option to capture, reinstate stripping by default in the capture methods #249
Add strip option to capture, reinstate stripping by default in the capture methods #249
Conversation
This reverses the decision made in capistrano#239. We now reinstate stripping by default to maintain backwards compatibility with the NetSSH backend, but support `strip: false` if full whitespace is needed.
Welcome to FOSS maintainer-ship of a popular project!
That's basically why I did it, although it's not a solid reason :) Capistrano could also be tweaked to strip the results of
Agreed, absolutely even though most people don't
Cool, good catch. |
Yes - totally! :) I'm trying to focus now on having SSHKit behave in the least surprising way.
I think this one is finely balanced, but I think your reasoning, to strip, makes sense in most situations, especially the trailing newline.
The thing about this is that it might make the documentation a bit confusing - if people read the SSHKit docs, Capistrano then does the opposite. I'm also thinking coding examples which work in Capistrano on Stack overflow etc, might not work in pure SSHKit. |
Looking back I think it would have been wiser to always document
You're right… let's wait for some other feedback from others, and then we might merge this. |
Yeah I agree. The thing I'm most worried about is this sort of usage (untested example): file_path = capture('ls -r1 | head -1')
execute("mv #{file_path} another_path") It seems like having a newline on the end of I agree would be good to get others' feelings - maybe @townsen, @mattbrictson if you have time? |
I agree with most of what has been said regarding the history of how this came to be, it was an understandable 'simplification', but I do feel that it was a mistake to strip any output. I have a few reasons for this:
But I think the above is easy to agree on, the question is what to do next! My opinion on that is:
I know this is a long reply, I hope it helps! Nick |
Yes, I agree with the points above too!
I like this idea. Maybe we should add an API cleanup wishlist .md file (or a long running issue?) where we can keep a note of things we want to fix for the next major version API.
I would appreciate that. I have made a number of other changes which should be backwards compatible, and if possible, I'd like to release them as a minor release and fix any problems I've introduced first. |
I agree with the proposal to strip by default, with new support for a As an anecdote, I tried doing a set :api_key, capture("grep ... awk ... etc etc")
...
execute "curl ... -F access_token=#{fetch(:api_key)} ..." The curl failed because somehow a semicolon was mysteriously inserted into the command string. Apparently there is some magic in cap or sshkit that translates newlines into semicolons? Anyway, it took me a while to finally trace the issue back to the fact that the Long story short: I think this change will cause confusion. 😉 Better save it for a major version number release. |
Update to reflect new `strip: false` option on the capture method
c242430
to
c77b398
Compare
OK, consensus seems to be that it would be good to leave the breaking API change until the next major release. I introduced a new file - |
Excellent thought @robd :) |
Cool. I think we have agreement on this, so would it be possible to merge this? |
Add strip option to capture, reinstate stripping by default in the capture methods
Thanks for the teamwork chaps. |
This reverts commit ad8682d. The original change to SSHKit which made stripping necessary was reverted in capistrano/sshkit#249, so we no longer need to strip in capistrano.
This reverts commit ad8682d. The original change to SSHKit which made stripping necessary was reverted in capistrano/sshkit#249, so we no longer need to strip in capistrano.
## 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)
This reverts commit ad8682de34ac78ba69da1569fe0fcdfa3014dc6d. The original change to SSHKit which made stripping necessary was reverted in capistrano/sshkit#249, so we no longer need to strip in capistrano.
This reverts commit ad8682de34ac78ba69da1569fe0fcdfa3014dc6d. The original change to SSHKit which made stripping necessary was reverted in capistrano/sshkit#249, so we no longer need to strip in capistrano.
This reverts commit ad8682de34ac78ba69da1569fe0fcdfa3014dc6d. The original change to SSHKit which made stripping necessary was reverted in capistrano/sshkit#249, so we no longer need to strip in capistrano.
I am nervous about the decision we made over in #239, to no longer strip the output of
capture
. Having seen some of the issues that are raised, I think there might be quite a lot of fallout from this. I'm particularly worried that this may not fail in an easy-to-understand way, and that we may waste a lot of everyones time dealing with them. I also think that in many cases, eg the one liners in Capistrano, stripping is a reasonable default.I do still think that we should make the API consistent between the
Local
andNetSSH
backends. Therefore, I'd like to propose that we make stripping whitespace the default, but add an option to the capture method to turn off stripping.@townsen Would you be OK with adding the
strip: false
option in the Local cases where you need full whitespace?This PR also adds some docs for the basic SSHKit usage, which I believe were sort of missing from the README.