ssh-kit-formatter 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ssh-kit-formatter.rb +81 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a4289ce6666b52fb8634bf92673c550cfa2ea0f3
|
4
|
+
data.tar.gz: 443031c17f076dd49cb5a995b5e13833964155bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45c6f57dc5a38e2cacb2daed0cba273e6ff47857b72ecbca374639522be430bd6fa29eef7104372205a90637ae153b88a8d508ad0f9ff9124220f55dc9e251d5
|
7
|
+
data.tar.gz: adbb74adb79d49971a5b3cec37d56c103b5a1487e96d28f35a7d06d680638b8d3cbff0d6f540c8bf387830df0b5b2056711ade3f9ac0110b1ab7bbc334ae536e
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'term/ansicolor'
|
2
|
+
|
3
|
+
module SSHKit
|
4
|
+
|
5
|
+
module Formatter
|
6
|
+
|
7
|
+
class Hostname < Abstract
|
8
|
+
|
9
|
+
def write(obj)
|
10
|
+
return if obj.verbosity < SSHKit.config.output_verbosity
|
11
|
+
case obj
|
12
|
+
when SSHKit::Command then write_command(obj)
|
13
|
+
when SSHKit::LogMessage then write_log_message(obj)
|
14
|
+
else
|
15
|
+
original_output << c.black(c.on_yellow("Output formatter doesn't know how to handle #{obj.class}\n"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
alias :<< :write
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def write_command(command)
|
23
|
+
unless command.started?
|
24
|
+
original_output << level(command.verbosity) + uuid(command) + "Running #{c.blue(command.host.to_s)} #{c.yellow(c.bold(String(command)))}\n"
|
25
|
+
if SSHKit.config.output_verbosity == Logger::DEBUG
|
26
|
+
original_output << level(Logger::DEBUG) + uuid(command) + "- #{c.blue(command.host.to_s)} Command: #{c.blue(command.to_command)}" + "\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if SSHKit.config.output_verbosity == Logger::DEBUG
|
31
|
+
unless command.stdout.empty?
|
32
|
+
command.stdout.lines.each do |line|
|
33
|
+
original_output << level(Logger::DEBUG) + uuid(command) + c.green("- #{c.blue(command.host.to_s)}\t" + line)
|
34
|
+
original_output << "\n" unless line[-1] == "\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
unless command.stderr.empty?
|
39
|
+
command.stderr.lines.each do |line|
|
40
|
+
original_output << level(Logger::DEBUG) + uuid(command) + c.red("- #{c.blue(command.host.to_s)}\t" + line)
|
41
|
+
original_output << "\n" unless line[-1] == "\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if command.finished?
|
47
|
+
original_output << level(command.verbosity) + uuid(command) + "- #{c.blue(command.host.to_s)} Finished in #{sprintf('%5.3f seconds', command.runtime)} with exit status #{command.exit_status} (#{c.bold { command.failure? ? c.red('failed') : c.green('successful') }}).\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def write_log_message(log_message)
|
52
|
+
original_output << level(log_message.verbosity) + log_message.to_s + "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def c
|
56
|
+
@c ||= Term::ANSIColor
|
57
|
+
end
|
58
|
+
|
59
|
+
def uuid(obj)
|
60
|
+
"[#{c.green(obj.uuid)}] "
|
61
|
+
end
|
62
|
+
|
63
|
+
def level(verbosity)
|
64
|
+
# Insane number here accounts for the control codes added
|
65
|
+
# by term-ansicolor
|
66
|
+
sprintf "%14s ", c.send(level_formatting(verbosity), level_names(verbosity))
|
67
|
+
end
|
68
|
+
|
69
|
+
def level_formatting(level_num)
|
70
|
+
%w{ black blue yellow red red }[level_num]
|
71
|
+
end
|
72
|
+
|
73
|
+
def level_names(level_num)
|
74
|
+
%w{ DEBUG INFO WARN ERROR FATAL }[level_num]
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssh-kit-formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brecht Hoflack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: brecht.hoflack@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ssh-kit-formatter.rb
|
20
|
+
homepage: http://github.com/bhoflack/ssh-kit-formatter
|
21
|
+
licenses:
|
22
|
+
- bsd
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Ssh kit formatter with hostname
|
44
|
+
test_files: []
|