class Kanrisuru::Command
Attributes
exit_status[R]
program[R]
raw_result[R]
remote_env[W]
remote_path[W]
remote_shell[W]
remote_user[W]
Public Class Methods
new(command)
click to toggle source
# File lib/kanrisuru/command.rb, line 8 def initialize(command) @valid_exit_codes = [0] @raw_command = command @raw_result = [] end
Public Instance Methods
+(other)
click to toggle source
# File lib/kanrisuru/command.rb, line 71 def +(other) append_value(other) end
<<(value)
click to toggle source
# File lib/kanrisuru/command.rb, line 75 def <<(value) append_value(value) end
append_arg(arg, string)
click to toggle source
# File lib/kanrisuru/command.rb, line 91 def append_arg(arg, string) @raw_command = Kanrisuru::Util.present?(string) ? "#{@raw_command} #{arg} #{string}" : @raw_command end
append_flag(arg, boolean = 'true')
click to toggle source
# File lib/kanrisuru/command.rb, line 95 def append_flag(arg, boolean = 'true') @raw_command = Kanrisuru::Util.present?(boolean) ? "#{@raw_command} #{arg}" : @raw_command end
append_valid_exit_code(code)
click to toggle source
# File lib/kanrisuru/command.rb, line 99 def append_valid_exit_code(code) @valid_exit_codes << code if code.instance_of?(Integer) @valid_exit_codes.concat(code) if code.instance_of?(Array) end
append_value(value)
click to toggle source
# File lib/kanrisuru/command.rb, line 87 def append_value(value) @raw_command = "#{@raw_command} #{value}" end
failure?()
click to toggle source
# File lib/kanrisuru/command.rb, line 18 def failure? !success? end
handle_data(data)
click to toggle source
# File lib/kanrisuru/command.rb, line 63 def handle_data(data) @raw_result.push(data) end
handle_signal(signal)
click to toggle source
# File lib/kanrisuru/command.rb, line 67 def handle_signal(signal) @signal = signal end
handle_status(status)
click to toggle source
# File lib/kanrisuru/command.rb, line 59 def handle_status(status) @exit_status = status end
pipe(value)
click to toggle source
# File lib/kanrisuru/command.rb, line 83 def pipe(value) append_value("| #{value}") end
prepared_command()
click to toggle source
# File lib/kanrisuru/command.rb, line 39 def prepared_command if !@remote_user.nil? && !@remote_shell.nil? evaluate = '' evaluate += if Kanrisuru::Util.present?(@remote_path) "cd #{@remote_path} && #{@raw_command}" else @raw_command.to_s end env = @remote_env && !@remote_env.empty? ? "#{@remote_env} " : '' "#{env}sudo -u #{@remote_user} #{@remote_shell} -c \"#{evaluate}\"" else @raw_command end end
raw_command()
click to toggle source
# File lib/kanrisuru/command.rb, line 55 def raw_command @raw_command.to_s end
success?()
click to toggle source
# File lib/kanrisuru/command.rb, line 14 def success? @valid_exit_codes.include?(@exit_status) end
to_a()
click to toggle source
# File lib/kanrisuru/command.rb, line 34 def to_a string = @raw_result.join string.lines.map(&:strip) end
to_i()
click to toggle source
# File lib/kanrisuru/command.rb, line 22 def to_i to_a.join.to_i end
to_json(*_args)
click to toggle source
# File lib/kanrisuru/command.rb, line 30 def to_json(*_args) JSON.parse(to_s) end
to_s()
click to toggle source
# File lib/kanrisuru/command.rb, line 26 def to_s to_a.join(' ') end
|(other)
click to toggle source
# File lib/kanrisuru/command.rb, line 79 def |(other) pipe(other) end