Class: Command::Flag
Constant Summary
collapse
- ATTRIBUTES =
%w(end delete)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CommandBase
execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids
Constructor Details
#initialize ⇒ Flag
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
|
# File 'lib/command/flag.rb', line 18
def initialize
super("<attribute> <target> [<target2> ...]")
@opt.separator <<-EOS.termcolor
<bold><red>非推奨のコマンドです。tagコマンドを使用して下さい
flagコマンドはv.1.7.0で廃止予定です
flagデータをtagデータに移行するには、
narou flag --convert-tag
を実行して下さい</red></bold>
・指定した小説に各種フラグを設定します
・再実行で解除
・--on, --off オプションを付けることで強制設定可能
・現在指定可能なフラグ
end : 小説が完結状態
delete: 削除された状態
Examples:
narou flag end 100 # ID:100の小説を完結状態にする
narou flag end --on 100 # 現在の状態に関わらず完結状態にする
Options:
EOS
@opt.on("--on", "強制的にフラグを立てる") {
@options["on"] = true
}
@opt.on("--off", "強制的にフラグをはずす") {
@options["off"] = true
}
@opt.on("--convert-tag", "flagデータをtagデータに移行します") {
modify = false
database = Database.instance
database.each do |id, data|
if data["flags"]
tags = data["flags"].keys
tags << "404" if tags.delete("delete")
unless tags.empty?
Tag.execute!([id, "--add", tags.join(" "), "--color", "white"])
end
puts "-" * 70
data.delete("flags")
modify = true
end
end
if modify
database.save_database
puts "移行が完了しました"
end
exit 0
}
end
|
Class Method Details
.oneline_help ⇒ Object
14
15
16
|
# File 'lib/command/flag.rb', line 14
def self.oneline_help
"小説の各種フラグを設定します"
end
|
Instance Method Details
#execute(argv) ⇒ Object
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
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/command/flag.rb', line 71
def execute(argv)
super
if argv.empty?
puts @opt.help
return
end
attribute = (argv.shift || "").downcase
unless ATTRIBUTES.include?(attribute)
error "有効なフラグを指定して下さい\n指定可能なフラグ:#{ATTRIBUTES.join(', ')}"
exit Narou::EXIT_ERROR_CODE
end
if argv.length < 1
error "対象小説を指定して下さい"
exit Narou::EXIT_ERROR_CODE
end
database = Database.instance
argv.each do |target|
data = Downloader.get_data_by_target(target)
unless data
error "#{target} は存在しません"
next
end
flags = data["flags"] || {}
flag = !flags[attribute]
flag = true if @options["on"]
flag = false if @options["off"]
flags[attribute] = flag
if flag
puts "#{data['title']} の #{attribute} フラグを立てました"
else
flags.delete(attribute)
puts "#{data['title']} から #{attribute} フラグをはずしました"
end
database[data["id"]]["flags"] = flags
end
database.save_database
end
|