Class: Saber::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



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

def initialize(*)
  super
  o = @o = options.dup

  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

Instance Attribute Details

#oObject (readonly)

Returns the value of attribute o.



13
14
15
# File 'lib/saber/cli.rb', line 13

def o
  @o
end

Instance Method Details

#cleanObject



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

def clean
  require "saber/task/clean"

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

#clientObject



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

def client
  AutoFetcher::Client.start
end

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



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

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



81
82
83
# File 'lib/saber/cli.rb', line 81

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

#generate(type, filename, *args) ⇒ Object



73
74
75
76
77
# File 'lib/saber/cli.rb', line 73

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

  Task["generate"].invoke(:generate, [options["tracker"] || ENV["SABER_TRACKER"], type, filename, *args], o)
end

#make(*files) ⇒ Object



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

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

  Task["make"].invoke(:make, [options["tracker"] || ENV["SABER_TRACKER"], *files], o)
end

#send1(*names) ⇒ Object



86
87
88
89
90
# File 'lib/saber/cli.rb', line 86

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

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

#serverObject



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

def server
  AutoFetcher::Server.start
end

#upload(*files) ⇒ Object



66
67
68
69
70
# File 'lib/saber/cli.rb', line 66

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

  Task["upload"].invoke(:upload, [options["tracker"] || ENV["SABER_TRACKER"], *files], o)
end