lib/miu/cli.rb in miu-0.1.0 vs lib/miu/cli.rb in miu-0.2.0

- old
+ new

@@ -1,13 +1,11 @@ require 'miu' +require 'miu/cli_base' require 'thor' module Miu - class CLI < ::Thor - include ::Thor::Actions - add_runtime_options! - + class CLI < CLIBase class << self def source_root File.expand_path('../../templates', __FILE__) end @@ -15,67 +13,94 @@ Miu.root end end map ['--version', '-v'] => :version - desc 'version', 'Show version' def version say "Miu #{Miu::VERSION}" end desc 'init', 'Generates a miu configuration files' def init - copy_file 'Gemfile' inside 'config' do template 'miu.god' end empty_directory 'log' empty_directory 'tmp/pids' end - desc 'list', 'Lists plugins' + desc 'list', 'Lists nodes' def list - require 'miu/plugins' - table = Miu.plugins.map { |k, v| [k, "# #{v}" ] } - say 'Plugins:' + table = Miu.nodes.map do |name, node| + [name, "# #{node.description}"] + end + say 'Nodes:' print_table table, :indent => 2, :truncate => true - say end - desc 'start', 'Start miu' + desc 'start', 'Start miu server' option 'pub-host', :type => :string, :default => '127.0.0.1', :desc => 'pub host' option 'pub-port', :type => :numeric, :default => Miu.default_pub_port, :desc => 'pub port' option 'sub-host', :type => :string, :default => '127.0.0.1', :desc => 'sub host' option 'sub-port', :type => :numeric, :default => Miu.default_sub_port, :desc => 'sub port' + option 'bridge-host', :type => :string, :default => '127.0.0.1', :desc => 'bridge host' + option 'bridge-port', :type => :numeric, :desc => 'bridge port' option 'verbose', :type => :boolean, :default => false, :desc => 'verbose output', :aliases => '-V' def start - server = Miu::Server.new Miu::Utility.optionalize_keys(options) + server = Miu::Server.new Miu::Utility.optionify_keys(options) server.run end - desc 'cat tag [body]', 'Nyan' + desc 'cat TAG ROOM TEXT', 'Okaka kakeyoune' option 'host', :type => :string, :default => '127.0.0.1', :desc => 'miu sub host' option 'port', :type => :numeric, :default => Miu.default_sub_port, :desc => 'miu sub port' - def cat(tag, body = nil) + option 'network', :type => :string, :default => 'debug', :desc => 'miu network name' + def cat(tag, room, text) + require 'miu/messages' require 'json' publisher = Miu::Publisher.new :host => options[:host], :port => options[:port] - publisher.connect - body = JSON.load(body) rescue body - publisher.send tag, body + message = Miu::Messages::Text.new do |m| + m.network.name = options[:network] + m.content.tap do |c| + c.room.name = room + c.text = text + end + end + + packet = publisher.write tag, message + Miu::Logger.info packet.inspect + rescue => e + Miu::Logger.exception e end - desc 'supervise', 'Supervise miu and plugins' + desc 'supervise', 'Supervise miu and nodes' def supervise(*args) - require 'god' - args.unshift "bundle exec god -c #{Miu.default_god_config}" - run args.join(' ') + args.unshift "-c #{Miu.default_god_config}" + run_god *args end - desc 'god', 'Miu is a god' + desc 'terminate', 'Terminate miu and nodes' + def terminate(*args) + args.unshift "-p #{Miu.default_god_port} terminate" + run_god *args + end + + desc 'god [ARGS]', 'Miu is a god' def god(*args) + args.unshift "-p #{Miu.default_god_port}" + run_god *args + end + + private + + def run_god(*args) require 'god' - args.unshift "bundle exec god -p #{Miu.default_god_port}" + args.unshift 'god' run args.join(' ') end end end + +# load miu nodes +Miu.load_nodes +