lib/saber/cli.rb in saber-1.1.1 vs lib/saber/cli.rb in saber-1.2.0
- old
+ new
@@ -5,40 +5,41 @@
include Thor::Actions
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 "force", banner: "Fore writing even if file exists", type: :boolean
class_option "tracker", aliases: "-t", banner: "tracker name", type: :string
+ class_option "dry-run", aliases: "-n", banner: "dry run", type: :boolean
- attr_reader :o
-
def initialize(*)
super
- o = @o = options.dup
+ self.options = self.options.dup
- Saber.ui = if o["log"] then
+ Saber.ui = if options["log"] then
require "logger"
- UI::Logger.new(::Logger.new(o["log"]))
+ UI::Logger.new(::Logger.new(options["log"]))
else
the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
UI::Shell.new(the_shell)
end
- Saber.ui.debug! if o["verbose"]
+ Saber.ui.debug! if options["verbose"]
# Initialize environment in first time
unless Rc.p.home.exists?
- Pa.mkdir Rc.p.home
+ Pa.mkdir Rc.p.home
+ Pa.mkdir "#{Rc.p.home}/templates"
+ Pa.mkdir "#{Rc.p.home}/database"
end
end
desc "clean", "clean up files doesn't in rtorrent client"
def clean
require "saber/task/clean"
- Task["clean"].invoke(:clean, [], o)
+ Task["clean"].invoke(:clean, [], options)
end
desc "server", "start saber-server daemon"
def server
AutoFetcher::Server.start
@@ -60,22 +61,29 @@
names = ids_str.split(",").map{|v| Retort::Torrent.action("name", v)}
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)
+ desc "upload [options] <format> <torrent_file/file ...>", "[make a torrent file and] upoad a torrent file to the site"
+ method_option "add", aliases: "-a", desc: "upload via add format.", type: :boolean
+ def upload(format0, *files)
require "saber/task/upload"
+ format = format0.downcase
+ Saber.ui.error! "Don't support this format -- #{format0}" unless Rc.book_exts.include?(".#{format}")
- Task["upload"].invoke(:upload, [options["tracker"] || ENV["SABER_TRACKER"], *files], o)
+ files = files.map{|v| v.dup} # unfrozen string.
+ Task["upload"].invoke(:upload, [options["tracker"] || ENV["SABER_TRACKER"], format, *wrap_file(*files)], options)
end
- desc "generate [options] <type> <filename> [arg ...]", %~generate a meta data file (alias: "g")~
- def generate(type, filename, *args)
+ desc "generate [options] <type> [filename:isbn ...]", %~generate a meta data file (alias: "g")~
+ method_option "file", aliases: "-f", desc: "read files from file list", type: :string
+ def generate(type, *files)
require "saber/task/generate"
- Task["generate"].invoke(:generate, [options["tracker"] || ENV["SABER_TRACKER"], type, filename, *args], o)
+ files = File.read(options["file"]).split(/\n+/).map{|v| v.strip} if options["file"]
+ files = files.map{|v| name, isbn = v.split(":"); [*wrap_file(name), isbn]}
+ Task["generate"].invoke(:generate, [type, *files], options)
end
map "g" => "generate"
desc "fetch [options] <file ..>", "fetch files from seedbox."
def fetch(*names)
@@ -84,23 +92,41 @@
desc "send1 <src ..> <dest>", "send files to seedbox"
def send1(*names)
require "saber/task/send"
- Task["send"].invoke(:send1, names, o)
+ Task["send"].invoke(:send1, names, options)
end
desc "make [options] <file ..>", "make a torent file and send it to local and/or remote watch directory"
+ method_option "option", aliases: "-o", desc: "extra options passed to mktorrent", type: :string
+ method_option "file", aliases: "-f", desc: "read files from file list", type: :string
def make(*files)
require "saber/task/make"
- Task["make"].invoke(:make, [options["tracker"] || ENV["SABER_TRACKER"], *files], o)
+ files = File.read(options["file"]).split(/\n+/).map{|v| v.strip.split(":")[0] } if options["file"]
+ Task["make"].invoke(:make, [options["tracker"] || ENV["SABER_TRACKER"], *files], options)
end
- desc "chd", "chd"
+ desc "chd", "NOT WORKING"
def chd
require "saber/task/chd"
- Task["chd"].invoke(:chd, o)
+ Task["chd"].invoke(:chd, [], options)
+ end
+
+ desc "find_uploads", "NOT WORKING"
+ def find_uploads(page)
+ require "saber/task/find_uploads"
+
+ Task["find_uploads"].invoke(:find_uploads, [page], options)
+ end
+
+ private
+
+ # a.yml -> a
+ # a.epub.torrent -> a
+ def wrap_file(*names)
+ names.map{|v| Pa.delete_ext(v, *%w[.torrent .yml]).delete_ext2(*Rc.book_exts)}
end
end
end