Class: Saber::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/saber/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/saber/cli.rb', line 14

def initialize(*)
  super
  self.options = self.options.dup

  Saber.ui = if options["log"] then
    require "logger"
    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 options["verbose"]

  # Initialize environment in first time
  unless Rc.p.home.exists?
    Pa.mkdir Rc.p.home 
    Pa.mkdir "#{Rc.p.home}/templates"
    Pa.mkdir "#{Rc.p.home}/database"
  end
end

Instance Method Details

#chdObject



111
112
113
114
115
# File 'lib/saber/cli.rb', line 111

def chd
  require "saber/task/chd"

  Task["chd"].invoke(:chd, [], options)
end

#cleanObject



37
38
39
40
41
# File 'lib/saber/cli.rb', line 37

def clean
  require "saber/task/clean"

  Task["clean"].invoke(:clean, [], options)
end

#clientObject



49
50
51
# File 'lib/saber/cli.rb', line 49

def client
  AutoFetcher::Client.start
end

#drb_add(ids_str, label = "") ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/saber/cli.rb', line 54

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)}

  AutoFetcher::DRbClient.new.add(*names)
end

#fetch(*names) ⇒ Object



89
90
91
# File 'lib/saber/cli.rb', line 89

def fetch(*names)
  Fetcher.new.add_names(*names)
end

#find_uploads(page) ⇒ Object



118
119
120
121
122
# File 'lib/saber/cli.rb', line 118

def find_uploads(page)
  require "saber/task/find_uploads"

  Task["find_uploads"].invoke(:find_uploads, [page], options)
end

#generate(type, *files) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/saber/cli.rb', line 79

def generate(type, *files)
  require "saber/task/generate"

  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

#make(*files) ⇒ Object



103
104
105
106
107
108
# File 'lib/saber/cli.rb', line 103

def make(*files)
  require "saber/task/make"

  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

#send1(*names) ⇒ Object



94
95
96
97
98
# File 'lib/saber/cli.rb', line 94

def send1(*names)
  require "saber/task/send"

  Task["send"].invoke(:send1, names, options)
end

#serverObject



44
45
46
# File 'lib/saber/cli.rb', line 44

def server
  AutoFetcher::Server.start
end

#upload(format0, *files) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/saber/cli.rb', line 68

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}")

  files = files.map{|v| v.dup} # unfrozen string.
  Task["upload"].invoke(:upload, [options["tracker"] || ENV["SABER_TRACKER"], format, *wrap_file(*files)], options)
end