sshkit 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +14 -0
- data/README.md +10 -0
- data/lib/sshkit/backends/netssh.rb +6 -2
- data/lib/sshkit/command.rb +12 -1
- data/lib/sshkit/configuration.rb +5 -1
- data/lib/sshkit/formatters/pretty.rb +7 -0
- data/lib/sshkit/version.rb +1 -1
- data/test/unit/backends/test_printer.rb +1 -1
- data/test/unit/test_command.rb +12 -0
- data/test/unit/test_configuration.rb +6 -0
- metadata +1 -1
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,20 @@
|
|
3
3
|
This file is written in reverse chronological order, newer releases will
|
4
4
|
appear at the top.
|
5
5
|
|
6
|
+
## 0.0.15
|
7
|
+
|
8
|
+
* `Command` now takes a `verbosity` option. This defaults to `Logger::INFO`
|
9
|
+
and can be set to any of the Ruby logger level constants. You can also set
|
10
|
+
it to the symbol `:debug` (and friends) which will be expanded into the correct
|
11
|
+
constants.
|
12
|
+
|
13
|
+
The log verbosity level is set to Logger::INFO by default, and can be
|
14
|
+
overridden by setting `SSHKit.config.output_verbosity = Logger::{...}`,
|
15
|
+
pick a level that works for you.
|
16
|
+
|
17
|
+
By default `test()` and `capture()` calls are surpressed, and not printed
|
18
|
+
by the pretty logger as of this version.
|
19
|
+
|
6
20
|
## 0.0.14
|
7
21
|
|
8
22
|
* Umasks can now be set on `Command` instances. It can be set globally with
|
data/README.md
CHANGED
@@ -173,6 +173,16 @@ on it's implementation it will almost certainly override the implementation of
|
|
173
173
|
`write()` (alias `<<()`) and query the objects it receives to determine what
|
174
174
|
should be printed.
|
175
175
|
|
176
|
+
## Verbosity
|
177
|
+
|
178
|
+
By default calls to `capture()` and `test()` are not logged, they are used
|
179
|
+
*so* frequently by backend tasks to check environmental settings that it
|
180
|
+
produces a large amount of noise. They are tagged with a verbosity option on
|
181
|
+
the `Command` instances of `Logger::DEBUG`. The default configuration for
|
182
|
+
output verbosity is avaialble to override with `SSHKit.config.output_verbosity=`,
|
183
|
+
and defaults to `Logger::INFO`.
|
184
|
+
|
185
|
+
At present the `Logger::WARN`, `ERROR` and `FATAL` are not used.
|
176
186
|
|
177
187
|
## Known Issues
|
178
188
|
|
@@ -16,7 +16,10 @@ module SSHKit
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test(*args)
|
19
|
-
options = args.extract_options!.merge(
|
19
|
+
options = args.extract_options!.merge(
|
20
|
+
raise_on_non_zero_exit: false,
|
21
|
+
verbosity: Logger::DEBUG
|
22
|
+
)
|
20
23
|
_execute(*[*args, options]).success?
|
21
24
|
end
|
22
25
|
|
@@ -30,7 +33,8 @@ module SSHKit
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def capture(*args)
|
33
|
-
|
36
|
+
options = args.extract_options!.merge(verbosity: Logger::DEBUG)
|
37
|
+
_execute(*[*args, options]).success?
|
34
38
|
end
|
35
39
|
|
36
40
|
def configure
|
data/lib/sshkit/command.rb
CHANGED
@@ -121,7 +121,18 @@ module SSHKit
|
|
121
121
|
options[:host]
|
122
122
|
end
|
123
123
|
|
124
|
-
def
|
124
|
+
def verbosity
|
125
|
+
if vb = options[:verbosity]
|
126
|
+
case vb.class.name
|
127
|
+
when 'Symbol' then return Logger.const_get(vb.to_s.upcase)
|
128
|
+
when 'Fixnum' then return vb
|
129
|
+
end
|
130
|
+
else
|
131
|
+
Logger::INFO
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def to_s(expanded=false)
|
125
136
|
return command.to_s if command.match /\s/
|
126
137
|
String.new.tap do |cs|
|
127
138
|
if options[:in]
|
data/lib/sshkit/configuration.rb
CHANGED
@@ -2,7 +2,7 @@ module SSHKit
|
|
2
2
|
|
3
3
|
class Configuration
|
4
4
|
|
5
|
-
attr_accessor :umask
|
5
|
+
attr_accessor :umask, :output_verbosity
|
6
6
|
attr_writer :output, :backend, :default_env, :command_map
|
7
7
|
|
8
8
|
def output
|
@@ -17,6 +17,10 @@ module SSHKit
|
|
17
17
|
@backend ||= SSHKit::Backend::Netssh
|
18
18
|
end
|
19
19
|
|
20
|
+
def output_verbosity
|
21
|
+
@output_verbosity ||= Logger::INFO
|
22
|
+
end
|
23
|
+
|
20
24
|
def format=(format)
|
21
25
|
formatter = SSHKit::Formatter.const_get(format.capitalize)
|
22
26
|
self.output = formatter.new($stdout)
|
@@ -8,22 +8,29 @@ module SSHKit
|
|
8
8
|
|
9
9
|
def write(obj)
|
10
10
|
if obj.is_a? SSHKit::Command
|
11
|
+
|
12
|
+
return if obj.verbosity < SSHKit.config.output_verbosity
|
13
|
+
|
11
14
|
unless obj.started?
|
12
15
|
original_output << "[#{c.green(obj.uuid)}] Running #{c.yellow(c.bold(String(obj)))} on #{c.yellow(obj.host.to_s)}\n"
|
13
16
|
end
|
17
|
+
|
14
18
|
if obj.complete? && !obj.stdout.empty?
|
15
19
|
obj.stdout.lines.each do |line|
|
16
20
|
original_output << c.green("\t" + line)
|
17
21
|
end
|
18
22
|
end
|
23
|
+
|
19
24
|
if obj.complete? && !obj.stderr.empty?
|
20
25
|
obj.stderr.lines.each do |line|
|
21
26
|
original_output << c.red("\t" + line)
|
22
27
|
end
|
23
28
|
end
|
29
|
+
|
24
30
|
if obj.finished?
|
25
31
|
original_output << "[#{c.green(obj.uuid)}] Finished in #{sprintf('%5.3f seconds', obj.runtime)} command #{c.bold { obj.failure? ? c.red('failed') : c.green('successful') }}.\n"
|
26
32
|
end
|
33
|
+
|
27
34
|
else
|
28
35
|
original_output << c.black(c.on_yellow("Output formatter doesn't know how to handle #{obj.inspect}\n"))
|
29
36
|
end
|
data/lib/sshkit/version.rb
CHANGED
@@ -37,7 +37,7 @@ module SSHKit
|
|
37
37
|
cd /opt/sites/example.com && /usr/bin/env ls -l /some/directory
|
38
38
|
if test ! -d /opt/sites/example.com/tmp; then echo "Directory does not exist '/opt/sites/example.com/tmp'" 1>&2; false; fi
|
39
39
|
if ! sudo su root -c whoami > /dev/null; then echo "You cannot switch to user 'root' using sudo, please check the sudoers file" 1>&2; false; fi
|
40
|
-
cd /opt/sites/example.com/tmp && ( RAILS_ENV=production sudo su root -c /usr/bin/env touch restart.txt )
|
40
|
+
cd /opt/sites/example.com/tmp && ( RAILS_ENV=production sudo su root -c \"/usr/bin/env touch restart.txt\" )
|
41
41
|
EOEXPECTED
|
42
42
|
end
|
43
43
|
|
data/test/unit/test_command.rb
CHANGED
@@ -120,6 +120,18 @@ module SSHKit
|
|
120
120
|
assert_equal "cd /var && ( A=b sudo su bob -c \"umask 007 && /usr/bin/env touch somefile\" )", String(c)
|
121
121
|
end
|
122
122
|
|
123
|
+
def test_verbosity_defaults_to_logger_info
|
124
|
+
assert_equal Logger::INFO, Command.new(:ls).verbosity
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_overriding_verbosity_level_with_a_constant
|
128
|
+
assert_equal Logger::DEBUG, Command.new(:ls, verbosity: Logger::DEBUG).verbosity
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_overriding_verbosity_level_with_a_symbol
|
132
|
+
assert_equal Logger::DEBUG, Command.new(:ls, verbosity: :debug).verbosity
|
133
|
+
end
|
134
|
+
|
123
135
|
def test_complete?
|
124
136
|
c = Command.new(:whoami, raise_on_non_zero_exit: false)
|
125
137
|
refute c.complete?
|
@@ -21,6 +21,12 @@ module SSHKit
|
|
21
21
|
assert_equal '007', SSHKit.config.umask
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_output_verbosity
|
25
|
+
assert_equal Logger::INFO, SSHKit.config.output_verbosity
|
26
|
+
assert SSHKit.config.output_verbosity = Logger::DEBUG
|
27
|
+
assert_equal Logger::DEBUG, SSHKit.config.output_verbosity
|
28
|
+
end
|
29
|
+
|
24
30
|
def test_default_env
|
25
31
|
assert SSHKit.config.default_env
|
26
32
|
end
|