lib/ztk/command.rb in ztk-0.3.1 vs lib/ztk/command.rb in ztk-1.0.0.rc.0
- old
+ new
@@ -15,11 +15,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
-
require "ostruct"
require "timeout"
module ZTK
@@ -48,15 +47,10 @@
:ignore_exit_status => false
}.merge(configuration))
config.logger.debug { "config=#{config.send(:table).inspect}" }
end
- def inspect
- @hostname ||= %x(hostname -f).chomp
- "#{ENV['USER']}@#{@hostname}"
- end
-
# Executes a local command.
#
# @param [String] command The command to execute.
# @param [Hash] options The options hash for executing the command.
#
@@ -67,24 +61,21 @@
# @example Execute a command:
#
# cmd = ZTK::Command.new
# puts cmd.exec("hostname -f").inspect
def exec(command, options={})
-
- def log_header(tag)
- count = 8
- sep = ("=" * count)
- header = [sep, "[ #{tag} ]", sep, "[ #{self.inspect} ]", sep, "[ #{tag} ]", sep].join
- "#{header}\n"
- end
-
options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(options))
config.logger.debug { "config=#{config.send(:table).inspect}" }
config.logger.debug { "options=#{options.send(:table).inspect}" }
config.logger.info { "command(#{command.inspect})" }
+ if config.replace_current_process
+ config.logger.fatal { "REPLACING CURRENT PROCESS - GOODBYE!" }
+ Kernel.exec(command)
+ end
+
output = ""
exit_code = -1
stdout_header = false
stderr_header = false
@@ -167,15 +158,34 @@
log_and_raise(CommandError, "exec(#{command.inspect}, #{options.inspect}) failed! [#{exit_code}]")
end
OpenStruct.new(:output => output, :exit_code => exit_code)
end
+ # Not Supported
+ # @raise [CommandError] Not Supported
def upload(*args)
log_and_raise(CommandError, "Not Supported")
end
+ # Not Supported
+ # @raise [CommandError] Not Supported
def download(*args)
log_and_raise(CommandError, "Not Supported")
+ end
+
+
+ private
+
+ def tag
+ @hostname ||= %x(hostname -f).chomp
+ "#{ENV['USER']}@#{@hostname}"
+ end
+
+ def log_header(what)
+ count = 8
+ sep = ("=" * count)
+ header = [sep, "[ #{what} ]", sep, "[ #{tag} ]", sep, "[ #{what} ]", sep].join
+ "#{header}\n"
end
end
end