Class: Command::Update
- Inherits:
-
CommandBase
- Object
- CommandBase
- Command::Update
- Defined in:
- lib/command/update.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize ⇒ Update
constructor
A new instance of Update.
Methods inherited from CommandBase
execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids
Constructor Details
#initialize ⇒ Update
Returns a new instance of Update.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/command/update.rb', line 15 def initialize super("[<target> ...] [options]") @opt.separator <<-EOS ・管理対象の小説を更新します。 更新したい小説のNコード、URL、タイトル、IDもしくは別名を指定して下さい。 IDは #{@opt.program_name} list を参照して下さい。 ・対象を指定しなかった場合、すべての小説の更新をチェックします。 ・一度に複数の小説を指定する場合は空白で区切って下さい。 ・全て更新する場合、convert.no-openが設定されていなくても保存フォルダは開きません。 Examples: narou update # 全て更新 narou u # 短縮コマンド narou update 0 1 2 4 narou update n9669bk 異世界迷宮で奴隷ハーレムを narou update http://ncode.syosetu.com/n9669bk/ Options: EOS @opt.on("-n", "--no-convert", "変換をせずアップデートのみ実行する") { @options["no-convert"] = true } @opt.on("-a", "--convert-only-new-arrival", "新着のみ変換を実行する") { @options["convert-only-new-arrival"] = true } end |
Class Method Details
.oneline_help ⇒ Object
11 12 13 |
# File 'lib/command/update.rb', line 11 def self.oneline_help "小説を更新します" end |
Instance Method Details
#execute(argv) ⇒ Object
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/command/update.rb', line 43 def execute(argv) super mistook_count = 0 update_target_list = argv.dup no_open = false if update_target_list.empty? Database.instance.each_key do |id| update_target_list << id end no_open = true end tagname_to_ids(update_target_list) update_target_list.each_with_index do |target, i| = nil data = Downloader.get_data_by_target(target) if !data = "<bold><red>[ERROR]</red></bold> #{target} は管理小説の中に存在しません".termcolor elsif Narou.novel_frozen?(target) if argv.length > 0 = "ID:#{data["id"]} #{data["title"]} は凍結中です" else next end end Helper.print_horizontal_rule if i > 0 if puts mistook_count += 1 next end result = Downloader.start(target) case result.status when :ok unless @options["no-convert"] || (@options["convert-only-new-arrival"] && !result.new_arrivals) convert_argv = [target] convert_argv << "--no-open" if no_open Convert.execute!(convert_argv) end when :failed puts "ID:#{data["id"]} #{data["title"]} の更新は失敗しました" mistook_count += 1 when :canceled puts "ID:#{data["id"]} #{data["title"]} の更新はキャンセルされました" mistook_count += 1 when :none puts "#{data["title"]} に更新はありません" end end exit mistook_count if mistook_count > 0 rescue Interrupt puts "アップデートを中断しました" exit Narou::EXIT_ERROR_CODE end |