120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/inat-get/app/setup.rb', line 120
def parse_options!
options = {
:config => "~/.config/#{ INatGet::Info::NAME }.yml",
:maintenance => nil,
:maintenance_params => nil
}
opts = OptionParser::new do |o|
o.banner = "🌿 \e[1miNatGet v#{INatGet::Info::VERSION} (#{INatGet::Info::VERSION_ALIAS}):\e[0m #{INatGet::Info::DESCRIPTION}\n" +
" License: \e[1mGNU GPLv3+\e[0m (#{INatGet::Info::LICENSE_URL})\n" +
" Author: \e[1m#{INatGet::Info::AUTHOR}\e[0m (#{INatGet::Info::AUTHOR_URL})\n" +
" Homepage: \e[1m#{INatGet::Info::HOMEPAGE}\e[0m\n\n" +
"\e[1m Usage:\e[0m #{INatGet::Info::NAME} [options] ‹task› [‹task› ...]"
o.separator ''
o.separator "\e[1m Info Options:\e[0m"
o.on '-h', '--help', 'Show this help and exit.' do
puts opts.help
exit 0
end
o.on '--version', 'Show version and exit.' do
puts INatGet::Info::VERSION
exit 0
end
o.on '-i', '--info', 'Show information about DB status and API connection. Then exit.' do
options[:maintenance] = :info
end
o.on '--show-config', 'Show current configuration and exit.' do
options[:maintenance] = :show_config
end
o.separator ''
o.separator "\e[1m Main Options:\e[0m"
o.on '-c', '--config FILE', String, 'Use this file as config (must be YAML) [default: ~/.config/inat-get.yml].' do |value|
options[:config] = value
end
o.on '-l', '--log-level LEVEL', [ 'fatal', 'error', 'warn', 'info', 'debug' ], 'Log level (fatal, error, warn, info or debug).' do |value|
options[:logs] ||= {}
options[:logs][:screen] ||= {}
options[:logs][:screen][:api] = value
options[:logs][:screen][:sys] = value
options[:logs][:screen][:wrk] = value
end
o.on '-L', '--log-file [FILE]', String, 'Set log file path (if specified) and enable logging to file.' do |value|
options[:logs] ||= {}
options[:logs][:file] ||= {}
options[:logs][:file][:path] = value if value
options[:logs][:file][:enable] = true
end
o.on '--file-log-level LEVEL', [ 'fatal', 'error', 'warn', 'info', 'debug' ], 'Log level for file logging (fatal, error, warn, info or debug).' do |value|
options[:logs] ||= {}
options[:logs][:file] ||= {}
options[:logs][:file][:api] = value
options[:logs][:file][:sys] = value
options[:logs][:file][:wrk] = value
end
o.on '--debug', 'Enable file logging and set file log level to debug.' do
options[:logs] ||= {}
options[:logs][:file] ||= {}
options[:logs][:file][:enable] = true
options[:logs][:file][:api] = 'debug'
options[:logs][:file][:sys] = 'debug'
options[:logs][:file][:wrk] = 'debug'
end
o.on '-o', '--offline', 'Offline mode: no updates, use local database only.' do
options[:offline] = true
end
o.on '-O', '--online', 'Online mode [default], use this flag to cancel \'offline: true\' in config.' do
options[:offline] = false
end
o.separator ''
o.separator "\e[1m DB Maintenance:\e[0m"
o.on '-C', '--db-check', 'Check DB version and exit.' do
options[:maintenance] = :db_check
end
o.on '-U', '--db-update', 'Migrate to latest DB version and exit.' do
options[:maintenance] = :db_update
end
o.on '-M', '--db-migrate VER', Integer, 'Migrate to DB version VER and exit.' do |value|
options[:maintenance] = :db_migrate
options[:maintenance_params] = value
end
o.on '--db-create', 'Create database (error if exists).' do
options[:maintenance] = :db_create
end
o.on '--db-reset', 'Drop (if exists) and recreate database. All fetched data will be lost.' do
options[:maintenance] = :db_reset
end
o.separator ''
o.separator "\e[1m File Arguments:\e[0m"
o.separator "\t‹task› [‹task› ...]\t One or more names of task files or list files with '@' prefix (one task\n" +
"\t\t\t\t file per line). If task name has not extension try to read '‹task›'\n" +
"\t\t\t\t than '‹task›.inat' than '‹task›.rb'."
end
begin
files = opts.parse!
rescue => e
$stderr.puts "❌ \e[1m#{ e.message }\e[0m"
exit Errno::ENOTSUP::Errno
end
[options, files]
end
|