class Telepath::CommandLine::Add

Public Instance Methods

execute() click to toggle source
# File lib/telepath/command.rb, line 47
def execute
  container = 'stack'
  values    = self.items || Array.new

  values << read_stdin if stdin?

  Out.error self, "No values supplied!" if values.empty?

  values.each do |value|
    handler.add value, container
    # check that value was added correctly, individually?
  end

  info values, container
end
info(values, container) click to toggle source
# File lib/telepath/command.rb, line 63
def info values, container
  value_text = values.length == 1 ? values.first : "[#{values.join ', '}]"
  Out.info "Added #{value_text} to #{container}!"
end
read_stdin() click to toggle source
# File lib/telepath/command.rb, line 68
def read_stdin
  $stdin.read.strip if stdin?
end
stdin?() click to toggle source
# File lib/telepath/command.rb, line 72
def stdin?
  if not $stdin.tty? then
    buffered = IO.select([$stdin], [], [], timeout)
    buffered && buffered.first && buffered.first.first
  end
end