Sha256: a91068f17c307fb74961e6752329abcb26a3cf5818581b4baa9eb6138592bd13

Contents?: true

Size: 1023 Bytes

Versions: 2

Compression:

Stored size: 1023 Bytes

Contents

require "del"
require "pathname"
require "thor"

module Del
  class CLI < Thor
    DEFAULT_RC=Pathname.new(Dir.home).join(".delrc")
    class_option :dotenv_file, default: ENV.fetch("DELRC", DEFAULT_RC)
    class_option :socket_file, default: Del::Configuration::SOCKET_FILE

    desc "server <routes.rb>", "start server"
    def server(startup_file = nil)
      Del.start(
        dotenv_file: options[:dotenv_file],
        socket_file: options[:socket_file],
        startup_file: startup_file,
      )
    end

    desc "message <jid> <message>", "send a message to the Jabber ID"
    def message(jid, message)
      socket = UNIXSocket.new(options[:socket_file])
      socket.puts(JSON.generate(command: :send_message, jid: jid, message: message))
      say socket.readline, :green
    rescue EOFError => error
      say error.message, :red
    rescue Errno::ECONNREFUSED => error
      say error.message, :red
      say "You must start the del server first.", :yellow
    ensure
      socket&.close
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
del-0.1.8 lib/del/cli.rb
del-0.1.7 lib/del/cli.rb