bookscan 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,7 @@ This is a scraper of Bookscan (http://www.bookscan.co.jp) Service.This is *NOT*
14
14
 
15
15
  * --debug
16
16
  * --help
17
+ * --version
17
18
 
18
19
  === Commands
19
20
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bookscan}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoshihiro TAKAHARA"]
@@ -13,6 +13,7 @@ module Bookscan
13
13
  def execute(argv)
14
14
  begin
15
15
  @opt = OptionParser.new
16
+ @opt.on('--version', 'show version') { version;exit }
16
17
  @opt.on('--help', 'show this message') { usage;exit }
17
18
  @opt.on('--debug', 'debug mode') { @options[:debug] = true }
18
19
  cmd_argv = @opt.order!(argv)
@@ -27,6 +28,16 @@ module Bookscan
27
28
 
28
29
  def usage(e=nil)
29
30
  puts @opt
31
+ puts "\nCommands:\n"
32
+ COMMANDS.each { |c|
33
+ puts " " + c
34
+ }
35
+ end
36
+
37
+ def version
38
+ File.open(File.dirname(__FILE__) + '/../../VERSION',"r") { |file|
39
+ puts file.gets
40
+ }
30
41
  end
31
42
 
32
43
  class << self
@@ -10,6 +10,9 @@ require "bookscan/agent"
10
10
  require "bookscan/cache"
11
11
 
12
12
  module Bookscan
13
+ COMMANDS = ["list","help", "login","logout","download","tune","update",
14
+ "groups","tuned"]
15
+
13
16
  class Commands
14
17
  def initialize(cmd_options,options)
15
18
  @options = options
@@ -17,9 +20,30 @@ module Bookscan
17
20
  @agent = Agent.new
18
21
  @cache_file = ENV['HOME']+"/.bookscan.cache"
19
22
  @cache = Cache.new(@cache_file)
23
+ @help = false
24
+ @banner = ""
25
+ end
26
+
27
+ def help
28
+ opt = OptionParser.new
29
+ opt.parse!(@command_options)
30
+ @banner = "command"
31
+ return opt if @help
32
+ @help = true
33
+ command = @command_options.shift
34
+ raise "Unknown command: " + command unless COMMANDS.include?(command)
35
+ opt = send(command)
36
+ opt.banner="Usage: bookscan [options] #{command} #{@banner}"
37
+ puts opt
38
+
20
39
  end
21
40
 
22
41
  def login
42
+ opt = OptionParser.new
43
+ opt.parse!(@command_options)
44
+ @banner = ""
45
+ return opt if @help
46
+
23
47
  email = ask('Enter email: ') do |q|
24
48
  q.validate = /\w+/
25
49
  end
@@ -44,24 +68,15 @@ module Bookscan
44
68
  end
45
69
 
46
70
  def logout
47
- Keystorage.delete("bookscan")
48
- end
71
+ opt = OptionParser.new
72
+ opt.parse!(@command_options)
73
+ @banner = ""
74
+ return opt if @help
49
75
 
50
- def start
51
- return true if @agent.login?
52
- email = Keystorage.list("bookscan").shift
53
- if email
54
- @agent.login(email,Keystorage.get("bookscan",email))
55
- unless @agent.login?
56
- login
57
- end
58
- else
59
- login
60
- end
76
+ Keystorage.delete("bookscan")
61
77
  end
62
78
 
63
79
  def update
64
- start
65
80
  all = false
66
81
  hash = false
67
82
 
@@ -73,7 +88,10 @@ module Bookscan
73
88
  hash = v
74
89
  end
75
90
  opt.parse!(@command_options)
91
+ @banner = ""
92
+ return opt if @help
76
93
 
94
+ start
77
95
  gs = @agent.groups
78
96
  if all
79
97
  gs.each_index do |index|
@@ -105,6 +123,10 @@ module Bookscan
105
123
  end
106
124
 
107
125
  def groups
126
+ opt = OptionParser.new
127
+ opt.parse!(@command_options)
128
+ @banner = ""
129
+ return opt if @help
108
130
  gs = @cache.groups
109
131
  puts gs.to_s
110
132
  end
@@ -119,6 +141,8 @@ module Bookscan
119
141
  opt.on('-t TYPE','--tuned=TYPE', 'download tuned') { |v| type = v; browsing = false }
120
142
  opt.on('-m PATTERN','--match=PATTERN','pattern match') { |v| pattern = v; browsing = false }
121
143
  opt.parse!(@command_options)
144
+ @banner = "[command options]"
145
+ return opt if @help
122
146
 
123
147
  if hash or browsing
124
148
  puts ask_group(hash,gs).books.to_s
@@ -152,6 +176,9 @@ module Bookscan
152
176
  dry_run = true
153
177
  end
154
178
  opt.parse!(@command_options)
179
+ @banner = "[command options] isbn|all"
180
+ return opt if @help
181
+
155
182
  book_id = @command_options.shift
156
183
 
157
184
  if book_id == "all"
@@ -206,6 +233,9 @@ module Bookscan
206
233
  pattern = v
207
234
  end
208
235
  opt.parse!(@command_options)
236
+ @banner = "[command options] isbn|all tune_type"
237
+ return opt if @help
238
+
209
239
  book_id = @command_options.shift
210
240
  type = ask_tune_type(@command_options.shift)
211
241
 
@@ -231,17 +261,40 @@ module Bookscan
231
261
  end
232
262
 
233
263
  def tuning
264
+ opt = OptionParser.new
265
+ opt.parse!(@command_options)
266
+ @banner = ""
267
+ return opt if @help
268
+
234
269
  start
235
270
  books = @agent.tuning
236
271
  puts books.to_s
237
272
  end
238
273
 
239
274
  def tuned
275
+ opt = OptionParser.new
276
+ opt.parse!(@command_options)
277
+ @banner = ""
278
+ return opt if @help
240
279
  puts @cache.tuned.to_s
241
280
  end
242
281
 
243
282
  private
244
283
 
284
+
285
+ def start
286
+ return true if @agent.login?
287
+ email = Keystorage.list("bookscan").shift
288
+ if email
289
+ @agent.login(email,Keystorage.get("bookscan",email))
290
+ unless @agent.login?
291
+ login
292
+ end
293
+ else
294
+ login
295
+ end
296
+ end
297
+
245
298
  def ask_group(hash,gs)
246
299
  unless hash
247
300
  puts gs.to_s
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookscan
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 3
10
+ version: 0.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yoshihiro TAKAHARA