Class: Del::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/del/cli.rb

Constant Summary collapse

DEFAULT_RC =
Pathname.new(Dir.home).join('.delrc')

Instance Method Summary collapse

Instance Method Details

#console(startup_file = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# 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) ⇒ Object



37
38
39
40
41
42
# 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) ⇒ Object



15
16
17
18
19
20
21
22
# 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

#setupObject



81
82
83
84
85
86
87
# 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) ⇒ Object



45
46
47
48
49
50
51
# 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

#usersObject



72
73
74
75
76
77
78
# 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

#versionObject



90
91
92
# File 'lib/del/cli.rb', line 90

def version
  say Del::VERSION, :green
end

#whoamiObject



54
55
56
57
58
59
60
# 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) ⇒ Object



63
64
65
66
67
68
69
# 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