class Del::CLI
Constants
- DEFAULT_RC
Public Instance Methods
console(startup_file = nil)
click to toggle source
# File lib/del/cli.rb, line 25 def console(startup_file = nil) require 'irb' Del.start(load_settings(start_server: false, startup_file: startup_file)) ARGV.clear IRB.start rescue Errno::ENOENT => error say error.message, :red say "run 'del setup'", :yellow end
message(jid, message)
click to toggle source
# File lib/del/cli.rb, line 37 def message(jid, message) SendMessage.new( self, socket_file: options[:socket_file] ).run(jid, message) end
server(startup_file = nil)
click to toggle source
# File lib/del/cli.rb, line 15 def server(startup_file = nil) Del.start(load_settings(start_server: true, startup_file: startup_file)) rescue Psych::DisallowedClass => error say error.message, :red rescue Errno::ENOENT => error say error.message, :red say "run 'del setup'", :yellow end
setup()
click to toggle source
# File lib/del/cli.rb, line 81 def setup yaml = YAML.dump(new_settings) IO.write(options[:configuration_file], yaml) File.chmod(0o600, options[:configuration_file]) say '' say "Configuration saved to: #{options[:configuration_file]}", :green end
status(status, message = nil)
click to toggle source
# File lib/del/cli.rb, line 45 def status(status, message = nil) socket = SocketMessage.new(self, socket_file: options[:socket_file]) socket.deliver(command: :change_status, status: status, message: message) say(socket.listen, :green) ensure socket.close end
users()
click to toggle source
# File lib/del/cli.rb, line 72 def users socket = SocketMessage.new(self, socket_file: options[:socket_file]) socket.deliver(command: :users) say(socket.listen, :green) ensure socket.close end
version()
click to toggle source
# File lib/del/cli.rb, line 90 def version say Del::VERSION, :green end
whoami()
click to toggle source
# File lib/del/cli.rb, line 54 def whoami socket = SocketMessage.new(self, socket_file: options[:socket_file]) socket.deliver(command: :whoami) say(socket.listen, :green) ensure socket.close end
whois(jid)
click to toggle source
# File lib/del/cli.rb, line 63 def whois(jid) socket = SocketMessage.new(self, socket_file: options[:socket_file]) socket.deliver(command: :whois, q: jid) say(socket.listen, :green) ensure socket.close end
Private Instance Methods
blank?(string)
click to toggle source
# File lib/del/cli.rb, line 119 def blank?(string) string.nil? || string.length.zero? end
load_settings(additional_settings)
click to toggle source
# File lib/del/cli.rb, line 106 def load_settings(additional_settings) settings = YAML.safe_load( IO.read(options[:configuration_file]), [Symbol], symbolize_names: true ) if blank?(settings[:password]) settings[:password] = ask('Password:', echo: false) end settings[:log_level] = options[:log_level] settings[:socket_file] = options[:socket_file] settings.merge(additional_settings) end
new_settings()
click to toggle source
# File lib/del/cli.rb, line 96 def new_settings { 'host' => ask("XMPP server: (E.g. 'chat.hipchat.com')"), 'jid' => ask('Jabber Id:'), 'muc_domain' => ask("MUC domain: (E.g. 'conf.hipchat.com')"), 'full_name' => ask('Name:'), 'password' => ask('Password:', echo: false) } end