bin/marvin in Sutto-marvin-0.2.0 vs bin/marvin in Sutto-marvin-0.2.1

- old
+ new

@@ -42,32 +42,53 @@ end say "Done!" end end + map "cl" => :client, "st" => :status, "rs" => :ring_server, + "dc" => :distributed_client, "co" => :console + desc "start [PATH]", "starts client at the given path" + method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean def start(path = ".") @dest = File.expand_path(path) - if File.exist?(source(@dest, "script/client")) - Dir.chdir(@dest) { exec "script/client" } - else - STDOUT.puts "Woops! #{@dest.gsub(" ", "\\ ")} doesn't look to be a marvin directory." - exit! - end + start_script(:client) end desc "status [PATH]", "shows status of marvin app at a given location" def status(path = ".") @dest = File.expand_path(path) - if File.exist?(source(@dest, "script/status")) - Dir.chdir(@dest) { exec "script/status" } - else - STDOUT.puts "Woops! #{@dest.gsub(" ", "\\ ")} doesn't look to be a marvin directory." - exit! - end + start_script(:status) end + desc "client [PATH]", "starts a client instance from the given location" + method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean + def client(path = ".") + @dest = File.expand_path(path) + start_script(:client) + end + + desc "ring_server [PATH]", "starts a ring server from the given location" + method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean + def ring_server(path = ".") + @dest = File.expand_path(path) + start_script(:ring_server) + end + + desc "distributed_client [PATH]", "starts a distributed client from the given location" + method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean + def distributed_client(path = ".") + @dest = File.expand_path(path) + start_script(:distributed_client) + end + + desc "console [PATH]", "starts a marvin console from the given location" + def console(path = ".") + @dest = File.expand_path(path) + start_script(:console) + end + private def source(*args) File.expand_path(File.join(*args)) end @@ -90,10 +111,29 @@ def say(text) STDOUT.puts text end + def marvin_repo?(path, type = client) + File.directory?(source(path, "script")) && File.exist?(source(path, "script/#{type}")) + end + + def start_script(name) + if marvin_repo?(@dest, name) + extra_args = [] + extra_args << "-k" if options[:kill] + extra_args << "-v" if options[:verbose] + extra_args << "-d" if options[:daemon] + extra_args << "--level=#{options[:level]}" if options[:level] + Dir.chdir(@dest) { exec("script/#{name}", *extra_args) } + else + STDOUT.puts "Woop! #{@dest.gsub(" ", "\\ ")} isn't a marvin app." + end + end + end + +STDOUT.puts "Marvin - IRC Library / Framework for Ruby" # Check if we have arguments, we run the normal # thor task otherwise we just print the help # message. if ARGV.empty? \ No newline at end of file