Sha256: 3c3cd5f9be1fcddb4373b4b76fb4c03d73d9287796873917b0cae2b29fdbf437
Contents?: true
Size: 1.56 KB
Versions: 14
Compression:
Stored size: 1.56 KB
Contents
require 'lino' require_relative 'base' require_relative 'mixins/environment' module RubyFly module Commands class Status < Base include Mixins::Environment def initialize(*args) super(*args) @stdout = StringIO.new unless (defined?(@stdout) && @stdout.respond_to?(:string)) @stderr = StringIO.new unless (defined?(@stderr) && @stderr.respond_to?(:string)) end def configure_command(builder, opts) builder = super(builder, opts) missing_params = [ :target ].select { |param| opts[param].nil? } unless missing_params.empty? description = missing_params.map { |p| "'#{p}'" }.join(', ') raise( ArgumentError, "Error: #{description} required but not provided.") end target = opts[:target] builder .with_subcommand('status') do |sub| sub = sub.with_option('-t', target) sub end end def do_around(opts, &block) begin block.call(opts) rescue Open4::SpawnError => e raise e unless e.status.exitstatus == 1 end end def do_after(opts) output = stdout.string error = stderr.string return :logged_in if output =~ /logged in successfully/ return :logged_out if error =~ /logged out/ return :session_expired if error =~ /please login again/ return :unknown_target if error =~ /error: unknown target/ :unknown_status end end end end
Version data entries
14 entries across 14 versions & 1 rubygems