-
Notifications
You must be signed in to change notification settings - Fork 0
/
books_sortby
executable file
·129 lines (102 loc) · 2.62 KB
/
books_sortby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env ruby19
# Bilal Syed Hussain
require 'rubygems'
require 'gli'
require "pp"
require File.join(File.dirname(__FILE__), 'books_lib')
# require_relative 'books_lib' #1.9 only
include GLI
program_desc 'iBooks sorting collections'
version 0.1
desc 'Reverse ordering'
switch [:r,:reverse]
desc 'List all collections with their ids'
arg_name 'ibooks_db'
command :list do |c|
c.action do |global_options,options,args|
raise "Usage #{c.usage}" unless args.length >=1
raise "File '#{args[0]}' does not exist." unless File.exists? args[0]
books = Books.new args[0]
books.list_collections
end
end
desc 'Moves all books from one collection to an another'
arg_name 'ibooks_db from to'
command :move do |c|
c.action do |global_options,options,args|
raise "Usage #{c.usage}" unless args.length ==3
raise "File '#{args[0]}' does not exist." unless File.exists? args[0]
begin
Integer(args[1])
Integer(args[2])
rescue Exception => e
raise "ids have to INTEGERS"
end
books = Books.new args[0]
books.move_all_books args[1], args[2]
end
end
desc 'Sort by Author (sort author)'
arg_name short_help
long_desc command_help
command :author do |c|
c.action do |global_options,options,args|
preform_actions c, global_options,options,args
end
end
desc 'Sort by Author (actual author)'
arg_name short_help
long_desc command_help
command :real_author do |c|
c.action do |global_options,options,args|
preform_actions c, global_options,options,args
end
end
desc 'Sort by Title'
arg_name short_help
long_desc command_help
command :title do |c|
c.action do |global_options,options,args|
preform_actions c, global_options,options,args
end
end
desc 'Sort by Sort Title'
arg_name short_help
long_desc command_help
command :sort_title do |c|
c.action do |global_options,options,args|
preform_actions c, global_options,options,args
end
end
desc 'Sort by Series'
arg_name short_help
long_desc command_help
command :series do |c|
c.action do |global_options,options,args|
preform_actions c, global_options,options,args
end
end
on_error do |exception|
# Error logic here
# return false to skip default error handling
true
end
pre do |global,command,options,args|
# Pre logic here
# Return true to proceed; false to abort and not call the
# chosen command
# Use skips_pre before a command to skip this block
# on that command only
true
end
post do |global,command,options,args|
# Post logic here
# Use skips_post before a command to skip this
# block on that command only
next if command.name == :help
# case command.name
# when :author
# pp command
# end
end
exit GLI.run(ARGV)