ztk 1.4.4 → 1.4.5
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/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/ztk.rb +3 -23
- data/lib/ztk/ansi.rb +94 -33
- data/lib/ztk/background.rb +4 -23
- data/lib/ztk/base.rb +5 -24
- data/lib/ztk/benchmark.rb +4 -23
- data/lib/ztk/command.rb +49 -40
- data/lib/ztk/config.rb +3 -22
- data/lib/ztk/dsl.rb +3 -22
- data/lib/ztk/dsl/base.rb +14 -22
- data/lib/ztk/dsl/core.rb +4 -24
- data/lib/ztk/dsl/core/actions.rb +1 -21
- data/lib/ztk/dsl/core/actions/find.rb +2 -22
- data/lib/ztk/dsl/core/actions/timestamps.rb +2 -22
- data/lib/ztk/dsl/core/attributes.rb +2 -22
- data/lib/ztk/dsl/core/dataset.rb +2 -22
- data/lib/ztk/dsl/core/io.rb +2 -22
- data/lib/ztk/dsl/core/relations.rb +2 -22
- data/lib/ztk/dsl/core/relations/belongs_to.rb +2 -22
- data/lib/ztk/dsl/core/relations/has_many.rb +2 -22
- data/lib/ztk/locator.rb +3 -22
- data/lib/ztk/logger.rb +2 -21
- data/lib/ztk/parallel.rb +4 -23
- data/lib/ztk/pty.rb +8 -23
- data/lib/ztk/report.rb +4 -23
- data/lib/ztk/rescue_retry.rb +4 -24
- data/lib/ztk/spinner.rb +6 -25
- data/lib/ztk/ssh.rb +20 -27
- data/lib/ztk/ssh/bootstrap.rb +17 -19
- data/lib/ztk/ssh/command.rb +1 -19
- data/lib/ztk/ssh/download.rb +1 -19
- data/lib/ztk/ssh/exec.rb +14 -24
- data/lib/ztk/ssh/file.rb +1 -19
- data/lib/ztk/ssh/upload.rb +5 -22
- data/lib/ztk/tcp_socket_check.rb +3 -22
- data/lib/ztk/template.rb +4 -23
- data/lib/ztk/ui.rb +5 -25
- data/lib/ztk/version.rb +1 -21
- data/spec/spec_helper.rb +1 -1
- data/spec/ztk/background_spec.rb +1 -1
- data/spec/ztk/base_spec.rb +1 -1
- data/spec/ztk/benchmark_spec.rb +1 -1
- data/spec/ztk/command_spec.rb +1 -1
- data/spec/ztk/config_spec.rb +1 -1
- data/spec/ztk/dsl_spec.rb +1 -1
- data/spec/ztk/locator_spec.rb +1 -1
- data/spec/ztk/logger_spec.rb +1 -1
- data/spec/ztk/parallel_spec.rb +1 -1
- data/spec/ztk/pty_spec.rb +1 -1
- data/spec/ztk/rescue_retry_spec.rb +1 -1
- data/spec/ztk/spinner_spec.rb +1 -1
- data/spec/ztk/ssh_spec.rb +1 -1
- data/spec/ztk/tcp_socket_check_spec.rb +1 -1
- data/spec/ztk/template_spec.rb +1 -1
- data/spec/ztk/ui_spec.rb +1 -1
- data/spec/ztk/version_spec.rb +1 -1
- data/ztk.gemspec +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -30,7 +30,7 @@ Issues:
|
|
30
30
|
|
31
31
|
ZTK - Zachary's (DevOp) Tool Kit
|
32
32
|
|
33
|
-
* Author: Zachary Patten <zachary
|
33
|
+
* Author: Zachary Patten <zachary AT jovelabs DOT com> [](http://coderwall.com/zpatten)
|
34
34
|
* Copyright: Copyright (c) Zachary Patten
|
35
35
|
* License: Apache License, Version 2.0
|
36
36
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
################################################################################
|
2
2
|
#
|
3
|
-
# Author: Zachary Patten <zachary
|
3
|
+
# Author: Zachary Patten <zachary AT jovelabs DOT com>
|
4
4
|
# Copyright: Copyright (c) Zachary Patten
|
5
5
|
# License: Apache License, Version 2.0
|
6
6
|
#
|
data/lib/ztk.rb
CHANGED
@@ -1,24 +1,4 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Author: Zachary Patten <zachary@jovelabs.net>
|
4
|
-
# Copyright: Copyright (c) Zachary Patten
|
5
|
-
# License: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
################################################################################
|
20
|
-
|
21
|
-
require "ztk/version"
|
1
|
+
require 'ztk/version'
|
22
2
|
|
23
3
|
# Main ZTK module
|
24
4
|
#
|
@@ -26,12 +6,12 @@ require "ztk/version"
|
|
26
6
|
# in mind. It provides several classes that ease SSH and SFTP, templating,
|
27
7
|
# and a myraid of other activities.
|
28
8
|
#
|
29
|
-
# @author Zachary Patten <zachary
|
9
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
30
10
|
module ZTK
|
31
11
|
|
32
12
|
# ZTK error class
|
33
13
|
#
|
34
|
-
# @author Zachary Patten <zachary
|
14
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
35
15
|
class Error < StandardError; end
|
36
16
|
|
37
17
|
autoload :Base, "ztk/base"
|
data/lib/ztk/ansi.rb
CHANGED
@@ -1,44 +1,25 @@
|
|
1
|
-
################################################################################
|
2
|
-
#
|
3
|
-
# Author: Zachary Patten <zachary@jovelabs.net>
|
4
|
-
# Copyright: Copyright (c) Zachary Patten
|
5
|
-
# License: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
################################################################################
|
20
1
|
module ZTK
|
21
2
|
|
22
3
|
# ANSI Error Class
|
23
|
-
#
|
4
|
+
#
|
5
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
24
6
|
class ANSIError < Error; end
|
25
7
|
|
26
8
|
# ANSI Mixin Module
|
27
9
|
#
|
28
|
-
#
|
10
|
+
# Standard use is to mix this module into String.
|
29
11
|
#
|
12
|
+
# @example Mix this module into String to enable easy ANSI coloring methods like:
|
30
13
|
# "bold red".red.bold
|
31
14
|
#
|
32
|
-
# Or
|
33
|
-
#
|
15
|
+
# @example Or
|
34
16
|
# "green".green
|
35
17
|
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# @author Zachary Patten <zachary@jovelabs.net>
|
18
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
39
19
|
module ANSI
|
40
20
|
|
41
|
-
|
21
|
+
# Defines our ANSI color codes
|
22
|
+
ANSI_COLORS = {
|
42
23
|
:black => 30,
|
43
24
|
:red => 31,
|
44
25
|
:green => 32,
|
@@ -49,20 +30,91 @@ module ZTK
|
|
49
30
|
:white => 37
|
50
31
|
}
|
51
32
|
|
52
|
-
|
33
|
+
# @!method black(string=nil, &block)
|
34
|
+
# Sets the foreground color to black for the supplied string.
|
35
|
+
# @param [String] string The string to operate on.
|
36
|
+
# @yieldreturn [String] The string to operate on.
|
37
|
+
# @return [String] The colored string.
|
38
|
+
#
|
39
|
+
# @!method red(string=nil, &block)
|
40
|
+
# Sets the foreground color to red for the supplied string.
|
41
|
+
# @param [String] string The string to operate on.
|
42
|
+
# @yieldreturn [String] The string to operate on.
|
43
|
+
# @return [String] The colored string.
|
44
|
+
#
|
45
|
+
# @!method green(string=nil, &block)
|
46
|
+
# Sets the foreground color to green for the supplied string.
|
47
|
+
# @param [String] string The string to operate on.
|
48
|
+
# @yieldreturn [String] The string to operate on.
|
49
|
+
# @return [String] The colored string.
|
50
|
+
#
|
51
|
+
# @!method yellow(string=nil, &block)
|
52
|
+
# Sets the foreground color to yellow for the supplied string.
|
53
|
+
# @param [String] string The string to operate on.
|
54
|
+
# @yieldreturn [String] The string to operate on.
|
55
|
+
# @return [String] The colored string.
|
56
|
+
#
|
57
|
+
# @!method blue(string=nil, &block)
|
58
|
+
# Sets the foreground color to blue for the supplied string.
|
59
|
+
# @param [String] string The string to operate on.
|
60
|
+
# @yieldreturn [String] The string to operate on.
|
61
|
+
# @return [String] The colored string.
|
62
|
+
#
|
63
|
+
# @!method magenta(string=nil, &block)
|
64
|
+
# Sets the foreground color to magenta for the supplied string.
|
65
|
+
# @param [String] string The string to operate on.
|
66
|
+
# @yieldreturn [String] The string to operate on.
|
67
|
+
# @return [String] The colored string.
|
68
|
+
#
|
69
|
+
# @!method cyan(string=nil, &block)
|
70
|
+
# Sets the foreground color to cyan for the supplied string.
|
71
|
+
# @param [String] string The string to operate on.
|
72
|
+
# @yieldreturn [String] The string to operate on.
|
73
|
+
# @return [String] The colored string.
|
74
|
+
#
|
75
|
+
# @!method white(string=nil, &block)
|
76
|
+
# Sets the foreground color to white for the supplied string.
|
77
|
+
# @param [String] string The string to operate on.
|
78
|
+
# @yieldreturn [String] The string to operate on.
|
79
|
+
# @return [String] The colored string.
|
80
|
+
|
81
|
+
# Defines our ANSI attribute codes
|
82
|
+
ANSI_ATTRIBUTES = {
|
53
83
|
:normal => 0,
|
54
84
|
:bold => 1
|
55
85
|
}
|
56
86
|
|
87
|
+
# @!method normal(string=nil, &block)
|
88
|
+
# Sets the foreground color to normal for the supplied string.
|
89
|
+
# @param [String] string The string to operate on.
|
90
|
+
# @yieldreturn [String] The string to operate on.
|
91
|
+
# @return [String] The colored string.
|
92
|
+
#
|
93
|
+
# @!method bold(string=nil, &block)
|
94
|
+
# Sets the foreground color to bold for the supplied string.
|
95
|
+
# @param [String] string The string to operate on.
|
96
|
+
# @yieldreturn [String] The string to operate on.
|
97
|
+
# @return [String] The colored string.
|
98
|
+
|
99
|
+
# Defines a RegEx for stripping ANSI codes from strings
|
57
100
|
ANSI_REGEX = /\e\[(?:(?:[349]|10)[0-7]|[0-9]|[34]8;5;\d{1,3})?m/
|
58
101
|
|
102
|
+
# Build ANSI Methods
|
103
|
+
#
|
104
|
+
# Dynamicly constructs our color methods based on the ANSI code hash passed
|
105
|
+
# in.
|
106
|
+
#
|
107
|
+
# @param [Hash] hash A hash where the keys represent the method names and
|
108
|
+
# the values are the ANSI codes.
|
109
|
+
# @return [Boolean] True if successful.
|
59
110
|
def build_ansi_methods(hash)
|
60
111
|
hash.each do |key, value|
|
61
112
|
define_method(key) do |string=nil, &block|
|
62
113
|
result = Array.new
|
114
|
+
|
63
115
|
result << %(\e[#{value}m)
|
64
116
|
if block_given?
|
65
|
-
result <<
|
117
|
+
result << block.call
|
66
118
|
elsif string.respond_to?(:to_str)
|
67
119
|
result << string.to_str
|
68
120
|
elsif respond_to?(:to_str)
|
@@ -75,11 +127,20 @@ module ZTK
|
|
75
127
|
result.join
|
76
128
|
end
|
77
129
|
end
|
130
|
+
|
131
|
+
true
|
78
132
|
end
|
79
133
|
|
80
|
-
|
134
|
+
# Uncolor String
|
135
|
+
#
|
136
|
+
# Removes ANSI code sequences from a string.
|
137
|
+
#
|
138
|
+
# @param [String] string The string to operate on.
|
139
|
+
# @yieldreturn [String] The string to operate on.
|
140
|
+
# @return [String] The supplied string stripped of ANSI codes.
|
141
|
+
def uncolor(string=nil, &block)
|
81
142
|
if block_given?
|
82
|
-
|
143
|
+
block.call.to_str.gsub(ANSI_REGEX, '')
|
83
144
|
elsif string.respond_to?(:to_str)
|
84
145
|
string.to_str.gsub(ANSI_REGEX, '')
|
85
146
|
elsif respond_to?(:to_str)
|
@@ -91,8 +152,8 @@ module ZTK
|
|
91
152
|
|
92
153
|
extend self
|
93
154
|
|
94
|
-
build_ansi_methods(
|
95
|
-
build_ansi_methods(
|
155
|
+
build_ansi_methods(ANSI_COLORS)
|
156
|
+
build_ansi_methods(ANSI_ATTRIBUTES)
|
96
157
|
|
97
158
|
end
|
98
159
|
|
data/lib/ztk/background.rb
CHANGED
@@ -1,29 +1,10 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Author: Zachary Patten <zachary@jovelabs.net>
|
4
|
-
# Copyright: Copyright (c) Zachary Patten
|
5
|
-
# License: Apache License, VersIOn 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, VersIOn 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissIOns and
|
17
|
-
# limitatIOns under the License.
|
18
|
-
#
|
19
|
-
################################################################################
|
20
|
-
require "base64"
|
1
|
+
require 'base64'
|
21
2
|
|
22
3
|
module ZTK
|
23
4
|
|
24
|
-
#
|
5
|
+
# Background Error Class
|
25
6
|
#
|
26
|
-
# @author Zachary Patten <zachary
|
7
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
27
8
|
class BackgroundError < Error; end
|
28
9
|
|
29
10
|
# Background Processing Class
|
@@ -99,7 +80,7 @@ module ZTK
|
|
99
80
|
# 1
|
100
81
|
# => nil
|
101
82
|
#
|
102
|
-
# @author Zachary Patten <zachary
|
83
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
103
84
|
class Background < ZTK::Base
|
104
85
|
|
105
86
|
# Result Set
|
data/lib/ztk/base.rb
CHANGED
@@ -1,32 +1,13 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Author: Zachary Patten <zachary@jovelabs.net>
|
4
|
-
# Copyright: Copyright (c) Zachary Patten
|
5
|
-
# License: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
################################################################################
|
20
|
-
require "ostruct"
|
1
|
+
require 'ostruct'
|
21
2
|
|
22
3
|
module ZTK
|
23
4
|
|
24
|
-
#
|
5
|
+
# Base Error Class
|
25
6
|
#
|
26
|
-
# @author Zachary Patten <zachary
|
7
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
27
8
|
class BaseError < Error; end
|
28
9
|
|
29
|
-
#
|
10
|
+
# Base Class
|
30
11
|
#
|
31
12
|
# This is the base class inherited by most of the other classes in this
|
32
13
|
# library. It provides a standard set of features to control STDOUT, STDERR
|
@@ -35,7 +16,7 @@ module ZTK
|
|
35
16
|
# You should never interact with this class directly; you should inherit it
|
36
17
|
# and extend functionality as appropriate.
|
37
18
|
#
|
38
|
-
# @author Zachary Patten <zachary
|
19
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
39
20
|
class Base
|
40
21
|
|
41
22
|
class << self
|
data/lib/ztk/benchmark.rb
CHANGED
@@ -1,32 +1,13 @@
|
|
1
|
-
################################################################################
|
2
|
-
#
|
3
|
-
# Author: Zachary Patten <zachary@jovelabs.net>
|
4
|
-
# Copyright: Copyright (c) Zachary Patten
|
5
|
-
# License: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
################################################################################
|
20
1
|
require 'benchmark'
|
21
2
|
|
22
3
|
module ZTK
|
23
4
|
|
24
|
-
#
|
5
|
+
# Benchmark Error Class
|
25
6
|
#
|
26
|
-
# @author Zachary Patten <zachary
|
7
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
27
8
|
class BenchmarkError < Error; end
|
28
9
|
|
29
|
-
#
|
10
|
+
# Benchmark Class
|
30
11
|
#
|
31
12
|
# This class contains a benchmarking tool which doubles to supply indications
|
32
13
|
# of activity to the console user during long running tasks.
|
@@ -55,7 +36,7 @@ module ZTK
|
|
55
36
|
# I wonder how long this will take? ...looks like it took 1.5229 seconds!
|
56
37
|
# => 1.522871547
|
57
38
|
#
|
58
|
-
# @author Zachary Patten <zachary
|
39
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
59
40
|
class Benchmark
|
60
41
|
|
61
42
|
class << self
|
data/lib/ztk/command.rb
CHANGED
@@ -1,70 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Author: Zachary Patten <zachary@jovelabs.net>
|
4
|
-
# Copyright: Copyright (c) Zachary Patten
|
5
|
-
# License: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
################################################################################
|
20
|
-
require "ostruct"
|
21
|
-
require "timeout"
|
1
|
+
require 'ostruct'
|
2
|
+
require 'timeout'
|
22
3
|
|
23
4
|
module ZTK
|
24
5
|
|
25
|
-
#
|
26
|
-
#
|
6
|
+
# Command Error Class
|
7
|
+
#
|
8
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
27
9
|
class CommandError < Error; end
|
28
10
|
|
29
11
|
# Command Execution Class
|
30
12
|
#
|
31
|
-
# We can get a new instance of Command like so:
|
32
|
-
#
|
13
|
+
# @example We can get a new instance of Command like so:
|
33
14
|
# cmd = ZTK::Command.new
|
34
15
|
#
|
35
|
-
# If we wanted to redirect STDOUT and STDERR to a StringIO we can do this:
|
36
|
-
#
|
16
|
+
# @example If we wanted to redirect STDOUT and STDERR to a StringIO we can do this:
|
37
17
|
# std_combo = StringIO.new
|
38
18
|
# ui = ZTK::UI.new(:stdout => std_combo, :stderr => std_combo)
|
39
|
-
# cmd = ZTK::Command.new(:ui => ui)
|
19
|
+
# cmd = ZTK::Command.new(:ui => ui, :silence => true)
|
20
|
+
# puts cmd.exec("hostname", :silence => false).inspect
|
40
21
|
#
|
41
|
-
# @author Zachary Patten <zachary
|
22
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
42
23
|
class Command < ZTK::Base
|
43
24
|
|
25
|
+
# @param [Hash] configuration Sets the overall default configuration for the
|
26
|
+
# class. For example, all calls to *exec* against this instance will use
|
27
|
+
# the configuration options specified here by default. These options can
|
28
|
+
# be overriden on a per call basis as well.
|
29
|
+
# @option configuration [Integer] :timeout (600) How long in seconds before
|
30
|
+
# the command will timeout.
|
31
|
+
# @option configuration [Boolean] :ignore_exit_status (false) Whether or not
|
32
|
+
# we should ignore the exit status of the the process we spawn. By
|
33
|
+
# default we do not ignore the exit status and throw an exception if it is
|
34
|
+
# non-zero.
|
35
|
+
# @option configuration [Integer] :exit_code (0) The exit code we expect the
|
36
|
+
# process to return. This is ignore if *ignore_exit_status* is true.
|
37
|
+
# @option configuration [Boolean] :silence (false) Whether or not we should
|
38
|
+
# squelch the output of the process. The output will always go to the
|
39
|
+
# logging device supplied in the ZTK::UI object. The output is always
|
40
|
+
# available in the return value from the method additionally.
|
44
41
|
def initialize(configuration={})
|
45
42
|
super({
|
46
43
|
:timeout => 600,
|
47
|
-
:ignore_exit_status => false
|
44
|
+
:ignore_exit_status => false,
|
45
|
+
:exit_code => 0,
|
46
|
+
:silence => false
|
48
47
|
}.merge(configuration))
|
49
48
|
config.ui.logger.debug { "config=#{config.send(:table).inspect}" }
|
50
49
|
end
|
51
50
|
|
52
|
-
#
|
51
|
+
# Execute Command
|
52
|
+
#
|
53
|
+
# @example Execute a command:
|
54
|
+
# cmd = ZTK::Command.new(:silence => true)
|
55
|
+
# puts cmd.exec("hostname", :silence => false).inspect
|
53
56
|
#
|
54
57
|
# @param [String] command The command to execute.
|
55
58
|
# @param [Hash] options The options hash for executing the command.
|
59
|
+
# @option options [Integer] :timeout (600) How long in seconds before
|
60
|
+
# the command will timeout.
|
61
|
+
# @option options [Boolean] :ignore_exit_status (false) Whether or not
|
62
|
+
# we should ignore the exit status of the the process we spawn. By
|
63
|
+
# default we do not ignore the exit status and throw an exception if it is
|
64
|
+
# non-zero.
|
65
|
+
# @option options [Integer] :exit_code (0) The exit code we expect the
|
66
|
+
# process to return. This is ignore if *ignore_exit_status* is true.
|
67
|
+
# @option options [Boolean] :silence (false) Whether or not we should
|
68
|
+
# squelch the output of the process. The output will always go to the
|
69
|
+
# logging device supplied in the ZTK::UI object. The output is always
|
70
|
+
# available in the return value from the method additionally.
|
56
71
|
#
|
57
72
|
# @return [OpenStruct#output] The output of the command, both STDOUT and
|
58
73
|
# STDERR combined.
|
59
74
|
# @return [OpenStruct#exit_code] The exit code of the process.
|
60
|
-
#
|
61
|
-
# @example Execute a command:
|
62
|
-
#
|
63
|
-
# cmd = ZTK::Command.new
|
64
|
-
# puts cmd.exec("hostname").inspect
|
65
|
-
#
|
66
75
|
def exec(command, options={})
|
67
|
-
options = OpenStruct.new(
|
76
|
+
options = OpenStruct.new(config.send(:table).merge(options))
|
68
77
|
|
69
78
|
options.ui.logger.debug { "config=#{options.send(:table).inspect}" }
|
70
79
|
options.ui.logger.debug { "options=#{options.send(:table).inspect}" }
|
@@ -177,14 +186,14 @@ module ZTK
|
|
177
186
|
private
|
178
187
|
|
179
188
|
# Returns a string in the format of "user@hostname" for the current
|
180
|
-
#
|
189
|
+
# shell.
|
181
190
|
def tag
|
182
191
|
@@hostname ||= %x(hostname).chomp
|
183
192
|
"#{ENV['USER']}@#{@hostname}"
|
184
193
|
end
|
185
194
|
|
186
195
|
# Formats a header suitable for writing to the direct logger when logging
|
187
|
-
#
|
196
|
+
# sessions.
|
188
197
|
def log_header(what)
|
189
198
|
count = 8
|
190
199
|
sep = ("=" * count)
|