Class: SleepRoom::CLI
- Inherits:
-
Object
- Object
- SleepRoom::CLI
- Defined in:
- lib/sleeproom/cli.rb
Instance Method Summary collapse
- #build ⇒ void
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ void
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sleeproom/cli.rb', line 10 def initialize(argv) SleepRoom.reload_config @options = {} build unless argv.empty? @parser.parse!(argv) action = argv.shift if action == "status" SleepRoom::Record::Tasks.status elsif action == "start" SleepRoom::Record::Tasks.start elsif action == "exit" SleepRoom::Record::Tasks.stop end exit(0) else puts @parser exit(0) end end |
Instance Method Details
#build ⇒ void
This method returns an undefined value.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sleeproom/cli.rb', line 37 def build @parser = OptionParser.new do |opt| opt.version = "SleepRoom / #{SleepRoom::VERSION}" opt. = "#{opt.version}" opt. += "\nUsage: sleeproom [Options]\n\n" opt. += "Action:\n" opt. += "status".rjust(10) opt. += "显示任务状态".rjust(33) opt. += "\n" opt. += "exit".rjust(8) opt. += "关闭任务队列".rjust(35) opt. += "\n\nCommands:\n" opt.on("-a ROOM, NAME", "--add ROOM, GROUP", Array, "添加到监视列表") do |room| SleepRoom::Record::Tasks.add(room[0].to_s, room[1].to_s) end opt.on("-r", "--remove [ROOM]", "从监视列表移除") do |room| SleepRoom::Record::Tasks.remove(room) end opt.on("-d", "--download [ROOM]", "录制指定房间") do |room| raise Error.new("房间名不能为空") if room.nil? if room.match?("https://www.showroom-live.com/") room = room.match(/https:\/\/www.showroom-live.com\/(.*)/)[1] end write_status = SleepRoom::Record::WriteStatus.new record = SleepRoom::Record::Showroom.new(room: room, group: "download", queue: write_status) record.record end opt.on("-v", "--verbose", "Print log") do @options[:verbose] = true end opt.on_tail("--version", "Print version") do STDOUT.puts(opt.version) end opt.on_tail("-h", "--help", "Print help") do STDOUT.puts(opt) end end end |