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



23
24
25
26
27
28
29
30
31
32
# File 'lib/del/cli.rb', line 23

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



35
36
37
38
39
40
# File 'lib/del/cli.rb', line 35

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
# File 'lib/del/cli.rb', line 15

def server(startup_file = nil)
  Del.start(load_settings(start_server: true, startup_file: startup_file))
rescue Errno::ENOENT => error
  say error.message, :red
  say "run 'del setup'", :yellow
end

#setupObject



79
80
81
82
83
84
85
# File 'lib/del/cli.rb', line 79

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



43
44
45
46
47
48
49
# File 'lib/del/cli.rb', line 43

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



70
71
72
73
74
75
76
# File 'lib/del/cli.rb', line 70

def users
  socket = SocketMessage.new(self, socket_file: options[:socket_file])
  socket.deliver(command: :users)
  say(socket.listen, :green)
ensure
  socket.close
end

#versionObject



88
89
90
# File 'lib/del/cli.rb', line 88

def version
  say Del::VERSION, :green
end

#whoamiObject



52
53
54
55
56
57
58
# File 'lib/del/cli.rb', line 52

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



61
62
63
64
65
66
67
# File 'lib/del/cli.rb', line 61

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