capistrano-simple-formatter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-simple-formatter.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-simple-formatter (0.2)
5
+ colored (~> 1.2)
6
+ highline (~> 1.6.21)
7
+ sshkit (~> 1.3)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ colored (1.2)
13
+ colorize (0.7.3)
14
+ highline (1.6.21)
15
+ net-scp (1.2.1)
16
+ net-ssh (>= 2.6.5)
17
+ net-ssh (2.9.1)
18
+ rake (10.3.2)
19
+ sshkit (1.5.1)
20
+ colorize
21
+ net-scp (>= 1.1.2)
22
+ net-ssh (>= 2.8.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.6)
29
+ capistrano-simple-formatter!
30
+ rake
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Rodrigo Díaz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Capistrano Simple Formatter
2
+
3
+ Simple formatter for Capistrano 3.
4
+
5
+ ## Installation
6
+
7
+ With bundler:
8
+
9
+ ```ruby
10
+ gem 'capistrano-simple-formatter'
11
+ ```
12
+
13
+ or without bundler:
14
+
15
+ ```ruby
16
+ $ gem install capistrano-simple-formatter
17
+
18
+ require 'capistrano-simple-formatter'
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Set the Capistrano `format` to `:simple`:
24
+
25
+ ```ruby
26
+ # deploy.rb
27
+
28
+ set :format, :simple
29
+ ```
30
+
31
+ Then, within any `task` block you can access the formatter through `SSHKit.config.output`, or just `output` within an `on` block.
32
+
33
+ ### Examples
34
+
35
+ Hook into Capistrano callbacks:
36
+
37
+ ```ruby
38
+ before('deploy:restart', :log_before_deploy_restart) do
39
+ SSHKit.config.output.start("Restarting apps")
40
+ end
41
+
42
+ after('deploy:restart', :log_after_deploy_restart) do
43
+ SSHKit.config.output.success
44
+ end
45
+ ```
46
+
47
+ Log on your tasks:
48
+
49
+ ```ruby
50
+ task(:link_files) do
51
+ on roles(:app) do
52
+ output.start "Linking files in #{host}"
53
+ # Do your work
54
+
55
+ if success
56
+ output.success
57
+ else
58
+ output.error 'Something went wrong :('
59
+ end
60
+ end
61
+ end
62
+ ```
63
+
64
+ Log nested:
65
+
66
+ ```ruby
67
+ namespace(:delayed_jobs) do
68
+ task(:status) do
69
+ SSHKit.config.output.start("Checking delayed_job status...") do
70
+ on roles(:apps), in: :parallel do
71
+ status = run_delayed_job_command(:status) # Your magic
72
+
73
+ if status.match(/delayed_job: no instances running/)
74
+ output.error "Not running in #{host}"
75
+ elsif matches = status.match(/delayed_job: running \[pid (?<pid>\d+)\]/)
76
+ output.success "Running in #{host} with pid #{matches[:pid]}"
77
+ else
78
+ output.info status
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ ```
85
+
86
+ ## TODO
87
+ * Output samples
88
+ * Examples file
89
+ * Specs
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+
5
+ require 'capistrano-simple-formatter'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'capistrano-simple-formatter'
9
+ spec.version = CapistranoSimpleFormatter::VERSION
10
+ spec.authors = ['Rodrigo Díaz V.']
11
+ spec.email = ['rdiazv89@gmail.com']
12
+ spec.summary = 'Simple formatter for logging Capistrano tasks'
13
+ spec.description = 'Simple formatter for logging Capistrano tasks'
14
+ spec.homepage = 'https://github.com/rdiazv/capistrano-simple-formatter'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'colored', '~> 1.2'
23
+ spec.add_dependency 'sshkit', '~> 1.3'
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ module CapistranoSimpleFormatter
4
+ class Spinner
5
+ CHARS = ['|', '/', '-', '\\']
6
+
7
+ def initialize
8
+ @running = false
9
+ end
10
+
11
+ def start
12
+ return if @running
13
+
14
+ @running = true
15
+ @thread = Thread.new do
16
+ while @running do
17
+ print CHARS.rotate!.first
18
+ sleep 0.1
19
+ print "\b"
20
+ end
21
+ end
22
+ end
23
+
24
+ def stop
25
+ return unless @running
26
+
27
+ @running = false
28
+ @thread.join
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module CapistranoSimpleFormatter
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'capistrano-simple-formatter/version'
2
+ require 'capistrano-simple-formatter/spinner'
3
+ require 'sshkit/formatter/simple'
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+
3
+ require 'sshkit'
4
+
5
+ module SSHKit
6
+ module Formatter
7
+ class Simple < Abstract
8
+ def initialize(original_output)
9
+ super(original_output)
10
+
11
+ @spinner = CapistranoSimpleFormatter::Spinner.new
12
+ @in_block = false
13
+ end
14
+
15
+ def start(message, &block)
16
+ @spinner.start
17
+
18
+ begin
19
+ if block_given?
20
+ @in_block = true
21
+ puts "\b#{message}".yellow
22
+ block.call()
23
+ stop
24
+ @in_block = false
25
+ else
26
+ print "\b#{message} ".yellow
27
+ end
28
+ rescue Exception => e
29
+ stop
30
+ @in_block = false
31
+ error("\n X ERROR: #{e.message}\n")
32
+ raise e
33
+ end
34
+ end
35
+
36
+ def stop
37
+ @spinner.stop
38
+ end
39
+
40
+ def result(message)
41
+ if @in_block
42
+ print "\b"
43
+ message = " ├── #{message}"
44
+ else
45
+ stop
46
+ end
47
+
48
+ puts(message)
49
+ end
50
+
51
+ def info(message)
52
+ result(message)
53
+ end
54
+
55
+ def error(message = 'X')
56
+ result(message.red)
57
+ end
58
+
59
+ def success(message = '✔')
60
+ result(message.green)
61
+ end
62
+
63
+ def write(message) end
64
+
65
+ alias :<< :write
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-simple-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Díaz V.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colored
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sshkit
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Simple formatter for logging Capistrano tasks
79
+ email:
80
+ - rdiazv89@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - capistrano-simple-formatter.gemspec
91
+ - lib/capistrano-simple-formatter.rb
92
+ - lib/capistrano-simple-formatter/spinner.rb
93
+ - lib/capistrano-simple-formatter/version.rb
94
+ - lib/sshkit/formatter/simple.rb
95
+ homepage: https://github.com/rdiazv/capistrano-simple-formatter
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.23
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Simple formatter for logging Capistrano tasks
120
+ test_files: []