lib/saber/cli.rb in saber-0.0.7 vs lib/saber/cli.rb in saber-1.0.0
- old
+ new
@@ -1,60 +1,99 @@
require "thor"
-require "drb"
module Saber
class CLI < Thor
include Thor::Actions
- class_option "no-color", :type => :boolean, :banner => "Disable colorization in output"
- class_option "verbose", :aliases => "-V", :type => :boolean, :banner => "Enable verbose output mode"
- class_option "log", :banner => "log file", :type => :string
+ class_option "no-color", banner: "Disable colorization in output", type: :boolean
+ class_option "verbose", aliases: "-V", banner: "Enable verbose output mode", type: :boolean
+ class_option "log", banner: "Log file", type: :string
+ class_option "force", aliases: "-f", banner: "Fore writing even if file exists", type: :boolean
+ class_option "tracker", aliases: "-t", banner: "tracker name", type: :string
attr_reader :o
def initialize(*)
super
o = @o = options.dup
- the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
- Saber.ui = UI::Shell.new(the_shell)
+
+ Saber.ui = if o["log"] then
+ require "logger"
+ UI::Logger.new(::Logger.new(o["log"]))
+ else
+ the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
+ UI::Shell.new(the_shell)
+ end
+
Saber.ui.debug! if o["verbose"]
+
+ # Initialize environment in first time
+ unless Rc.p.home.exists?
+ Pa.mkdir Rc.p.home
+ end
end
desc "clean", "clean up files doesn't in rtorrent client"
def clean
- Task.clean
- end
+ require "saber/task/clean"
- desc "add <file ..>", "begin download file or directory via aria2 daemon."
- def add(*names)
- Downloader.new.add_names(*names)
+ Task["clean"].invoke(:clean, [], o)
end
desc "server", "start saber-server daemon"
def server
- require "logger"
- o["log"] ||= "/var/log/saber-server.log"
-
- $log = Logger.new options["verbose"] ? STDOUT : o["log"]
- Server.start
+ AutoFetcher::Server.start
end
desc "client", "start saber-client daemon"
def client
- require "logger"
- o["log"] ||= "/var/log/saber-client.log"
-
- $log = Logger.new options["verbose"] ? STDOUT : o["log"]
- Client.start
+ AutoFetcher::Client.start
end
- desc "drb_add <ids> [label]", "add a file to saber-server daemon via drb"
- # drb_add "id1,id2", "foo"
- def drb_add(ids_str, label=Rc.label)
- return if label != Rc.label
+ desc "drb_add [options] <id,...> <label>", "add a file to saber-server daemon via drb."
+ def drb_add(ids_str, label="")
+ return if label != "saber"
+ require "drb"
+ require "retort"
+ Retort::Service.configure { |c| c.url = Rc.scgi_server }
+
names = ids_str.split(",").map{|v| Retort::Torrent.action("name", v)}
- DRbClient.new.add(*names)
+ AutoFetcher::DRbClient.new.add(*names)
+ end
+
+ desc "upload [options] <torrent_file/file ...>", "[make a torrent file and] upoad a torrent file to the site"
+ def upload(*files)
+ require "saber/task/upload"
+
+ Task["upload"].invoke(:upload, [options["tracker"] || ENV["SABER_TRACKER"], *files], o)
+ end
+
+ desc "generate [options] <type> <filename> [arg ...]", %~generate a meta data file (alias: "g")~
+ def generate(type, filename, *args)
+ require "saber/task/generate"
+
+ Task["generate"].invoke(:generate, [options["tracker"] || ENV["SABER_TRACKER"], type, filename, *args], o)
+ end
+ map "g" => "generate"
+
+ desc "fetch [options] <file ..>", "fetch files from seedbox."
+ def fetch(*names)
+ Fetcher.new.add_names(*names)
+ end
+
+ desc "send1 <src ..> <dest>", "send files to seedbox"
+ def send1(*names)
+ require "saber/task/send"
+
+ Task["send"].invoke(:send1, names, o)
+ end
+
+ desc "make [options] <file ..>", "make a torent file and send it to local and/or remote watch directory"
+ def make(*files)
+ require "saber/task/make"
+
+ Task["make"].invoke(:make, [options["tracker"] || ENV["SABER_TRACKER"], *files], o)
end
end
end