sshkit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
+ *.gem
1
2
  .vagrant
2
3
  test/tmp
data/CHANGELOG.md CHANGED
@@ -0,0 +1,15 @@
1
+ ## Changelog
2
+
3
+ This file is written in reverse chronological order, newer releases will
4
+ appear at the top.
5
+
6
+ ## 0.0.2
7
+
8
+ * Include a *Pretty* formatter
9
+ * Modify example to use Pretty formatter.
10
+ * Move common behaviour to an abstract formatter.
11
+ * Formatters no longer inherit StringIO
12
+
13
+ ## 0.0.1
14
+
15
+ First release.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deploy (0.0.1)
4
+ sshkit (0.0.1)
5
5
  net-ssh
6
6
  term-ansicolor
7
7
 
@@ -58,11 +58,11 @@ PLATFORMS
58
58
  DEPENDENCIES
59
59
  autotest
60
60
  debugger
61
- deploy!
62
61
  minitest (>= 2.11.3, < 2.12.0)
63
62
  mocha
64
63
  rake
65
64
  redcarpet
65
+ sshkit!
66
66
  turn
67
67
  unindent
68
68
  vagrant
data/example.rb CHANGED
@@ -7,53 +7,11 @@ $: << Dir.pwd + '/lib/'
7
7
  # Automatically sucks in the `sshkit`
8
8
  # files so that you don't need to.
9
9
  require 'sshkit/dsl'
10
- require 'forwardable'
11
- require 'term/ansicolor'
12
10
 
13
11
  directory = '/opt/sites/web_application'
14
12
  hosts = SSHKit::Host.new("root@example.com")
15
13
 
16
- #
17
- # Custom output formatter!
18
- #
19
- class ColorizedFormatter < StringIO
20
- extend Forwardable
21
- attr_reader :original_output
22
- def_delegators :@original_output, :read, :rewind
23
-
24
- def initialize(oio)
25
- @original_output = oio
26
- end
27
-
28
- def write(obj)
29
- if obj.is_a? SSHKit::Command
30
- unless obj.started?
31
- original_output << "[#{c.green(obj.uuid)}] Running #{c.yellow(c.bold(String(obj)))} on #{c.yellow(obj.host.to_s)}\n"
32
- end
33
- if obj.complete? && !obj.stdout.empty?
34
- obj.stdout.lines.each do |line|
35
- original_output << c.green("\t" + line)
36
- end
37
- end
38
- if obj.complete? && !obj.stderr.empty?
39
- obj.stderr.lines.each do |line|
40
- original_output << c.red("\t" + line)
41
- end
42
- end
43
- if obj.finished?
44
- 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"
45
- end
46
- else
47
- original_output << c.black(c.on_yellow("Output formatter doesn't know how to handle #{obj.inspect}\n"))
48
- end
49
- end
50
- private
51
- def c
52
- @c ||= Term::ANSIColor
53
- end
54
- end
55
-
56
- SSHKit.config.output = ColorizedFormatter.new($stdout)
14
+ SSHKit.config.output = SSHKit::Formatter::Pretty.new($stdout)
57
15
 
58
16
  on hosts do |host|
59
17
  target = '/opt/rack-rack-repository'
data/lib/sshkit/all.rb CHANGED
@@ -8,6 +8,10 @@ require_relative 'command'
8
8
  require_relative 'configuration'
9
9
  require_relative 'connection_manager'
10
10
 
11
+ require_relative 'formatters/abstract'
12
+ require_relative 'formatters/black_hole'
13
+ require_relative 'formatters/pretty'
14
+
11
15
  require_relative 'backends/abstract'
12
16
  require_relative 'backends/printer'
13
17
  require_relative 'backends/netssh'
@@ -0,0 +1,26 @@
1
+ require 'forwardable'
2
+
3
+ module SSHKit
4
+
5
+ module Formatter
6
+
7
+ class Abstract
8
+
9
+ extend Forwardable
10
+ attr_reader :original_output
11
+ def_delegators :@original_output, :read, :rewind
12
+
13
+ def initialize(oio)
14
+ @original_output = oio
15
+ end
16
+
17
+ def write(obj)
18
+ raise "Abstract formatter should not be used directly, maybe you want SSHKit::Formatter::BlackHole"
19
+ end
20
+ alias :<< :write
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,16 @@
1
+ module SSHKit
2
+
3
+ module Formatter
4
+
5
+ class BlackHole < Abstract
6
+
7
+ def write(obj)
8
+ # Nothing, nothing to do
9
+ end
10
+ alias :<< :write
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,43 @@
1
+ require 'term/ansicolor'
2
+
3
+ module SSHKit
4
+
5
+ module Formatter
6
+
7
+ class Pretty < Abstract
8
+
9
+ def write(obj)
10
+ if obj.is_a? SSHKit::Command
11
+ unless obj.started?
12
+ original_output << "[#{c.green(obj.uuid)}] Running #{c.yellow(c.bold(String(obj)))} on #{c.yellow(obj.host.to_s)}\n"
13
+ end
14
+ if obj.complete? && !obj.stdout.empty?
15
+ obj.stdout.lines.each do |line|
16
+ original_output << c.green("\t" + line)
17
+ end
18
+ end
19
+ if obj.complete? && !obj.stderr.empty?
20
+ obj.stderr.lines.each do |line|
21
+ original_output << c.red("\t" + line)
22
+ end
23
+ end
24
+ if obj.finished?
25
+ 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
+ end
27
+ else
28
+ original_output << c.black(c.on_yellow("Output formatter doesn't know how to handle #{obj.inspect}\n"))
29
+ end
30
+ end
31
+ alias :<< :write
32
+
33
+ private
34
+
35
+ def c
36
+ @c ||= Term::ANSIColor
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -1,3 +1,3 @@
1
1
  module SSHKit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -248,6 +248,9 @@ files:
248
248
  - lib/sshkit/configuration.rb
249
249
  - lib/sshkit/connection_manager.rb
250
250
  - lib/sshkit/dsl.rb
251
+ - lib/sshkit/formatters/abstract.rb
252
+ - lib/sshkit/formatters/black_hole.rb
253
+ - lib/sshkit/formatters/pretty.rb
251
254
  - lib/sshkit/host.rb
252
255
  - lib/sshkit/version.rb
253
256
  - sshkit.gemspec