Class: Esp::CLI
- Inherits:
-
Thor
show all
- Includes:
- Support
- Defined in:
- lib/esp/cli.rb,
lib/esp/cli/mcp.rb,
lib/esp/cli/docs.rb,
lib/esp/cli/i18n.rb,
lib/esp/cli/refs.rb,
lib/esp/cli/plugins.rb,
lib/esp/cli/support.rb
Defined Under Namespace
Modules: Support
Classes: Docs, I18nCli, Mcp, Plugins, Refs
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
9
|
# File 'lib/esp/cli.rb', line 9
def self.exit_on_failure? = true
|
Instance Method Details
#build(mod = nil) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/esp/cli.rb', line 139
def build(mod = nil)
fail_with(t('cli.build.usage')) if !options[:all] && mod.nil?
root = resolve_root
mods = options[:all] ? Esp::Mw::Builder.discover_mods(root: root) : [mod]
results = mods.map { |m| build_one(m, locale: options[:locale], root: root) }
installs = options[:install] ? mods.map { |m| install_one(m) } : []
respond({ results: results, installs: installs }) do
results.each do |r|
r[:logs].each { |line| say(line) }
say t('cli.build.done', mod: r[:mod], output: r[:output])
end
installs.each { |ins| say_install_actions(ins) }
end
end
|
#doctor ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/esp/cli.rb', line 24
def doctor
ruby_ok = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(Esp::MINIMUM_RUBY_VERSION)
tes3conv = tes3conv_path
refs_db = Esp::Mw::ReferenceIndex.default_db_path
refs_present = File.exist?(refs_db)
problems = [!ruby_ok, tes3conv.nil?].count(true)
payload = {
ruby: { version: RUBY_VERSION, required: Esp::MINIMUM_RUBY_VERSION, ok: ruby_ok },
esp: Esp::VERSION,
tes3conv: { found: !tes3conv.nil?, path: tes3conv },
references_index: { present: refs_present, path: refs_db },
problems: problems
}
respond(payload) { print_doctor(payload) }
exit(1) if problems.positive?
end
|
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/esp/cli.rb', line 221
def (mod)
result = Esp::Operations.dispatch(:extract_scripts, params_with_root('mod' => mod))
respond(result) do
result[:extracted].each { |id| say t('cli.extract_scripts.extracted', id: id) }
result[:skipped].each { |id| say t('cli.extract_scripts.skipped', id: id) }
say t('cli.extract_scripts.done', extracted: result[:extracted].size, skipped: result[:skipped].size)
end
rescue ArgumentError, Esp::Mw::Loader::LoadError, Esp::Operations::InputError => e
fail_with(e.message)
end
|
#init(name = nil) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/esp/cli.rb', line 47
def init(name = nil)
target = File.expand_path(name ? File.join(Dir.pwd, name) : Dir.pwd)
game = options[:game].to_s
unless Esp::Plugins.known?(game)
fail_with(t('errors.plugins.unknown_game',
game: game, known: Esp::Plugins.ids.join(', ')))
end
if Esp::ProjectMarker.find_in(target) && !options[:force]
fail_with(t('cli.init.already_initialised', path: target))
end
FileUtils.mkdir_p(File.join(target, 'mods'))
FileUtils.mkdir_p(File.join(target, 'dist'))
Esp::Vcs.run_git_init(target) unless File.directory?(File.join(target, '.git'))
ensure_default_gitignore(target)
Esp::ProjectMarker.write(target, name: File.basename(target), game: game)
respond({ root: target, game: game }) do
say t('cli.init.created', path: target, game: game)
say t('cli.init.next')
end
end
|
#install(mod) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/esp/cli.rb', line 164
def install(mod)
params = params_with_root(
'mod' => mod,
'copy_to' => options[:copy_to],
'to_data_files' => options[:to_data_files],
'register_openmw' => options[:register_openmw]
).compact
result = Esp::Operations.dispatch(:install, params)
respond(result) do
Array(result[:actions]).each do |a|
say(t(a[:added] ? 'cli.install.added' : 'cli.install.present', line: a[:line]))
end
say t('cli.install.copied', path: result[:copied_to]) if result[:copied_to]
say t('cli.install.done')
end
rescue Esp::Operations::InputError => e
fail_with(e.message)
end
|
#lint(mod) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/esp/cli.rb', line 184
def lint(mod)
result = Esp::Operations.dispatch(:lint, params_with_root('mod' => mod))
issues = result[:issues]
respond(result) do
if issues.empty?
say t('cli.lint.ok')
else
issues.each { |raw| say(format_issue(Esp::Mw::Linter::Issue.new(**raw))) }
say t('cli.lint.summary', errors: result[:errors], warnings: result[:warnings])
end
end
exit(1) if result[:errors].positive?
rescue Esp::Operations::InputError, Esp::Mw::Loader::LoadError => e
fail_with(e.message)
end
|
#new_mod(mod) ⇒ Object
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
|
# File 'lib/esp/cli.rb', line 95
def new_mod(mod)
root = resolve_root
result = Esp::Mw::Scaffolder.create(
mod,
format: options[:format],
author: options[:author],
description: options[:description],
force: options[:force],
root: root
)
relative = ->(p) { p.sub("#{root}/", '') }
payload = {
mod: result.mod,
format: result.format,
source: relative.call(result.source),
readme: relative.call(result.readme)
}
respond(payload) do
say t('cli.new.created', path: payload[:source])
say t('cli.new.created', path: payload[:readme])
say t('cli.new.next', mod: result.mod)
end
rescue ArgumentError => e
fail_with(e.message)
end
|
#serve ⇒ Object
212
213
214
215
216
217
|
# File 'lib/esp/cli.rb', line 212
def serve
server = Esp::HttpServer.new(port: options[:port])
say t('cli.serve.listening', port: options[:port])
say t('cli.serve.routes')
server.start
end
|
#setup ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/esp/cli.rb', line 73
def setup
configured = []
Dir.chdir(Esp::ROOT) do
{ 'diff.tes3.textconv' => 'tes3conv',
'diff.tes3.binary' => 'true',
'core.hooksPath' => '.githooks' }.each do |key, value|
system('git', 'config', key, value, exception: true)
configured << { key: key, value: value }
end
end
respond({ configured: configured }) do
say t('cli.setup.diff_driver')
say t('cli.setup.hooks_path')
end
end
|
#unpack(plugin, name = nil) ⇒ Object
123
124
125
126
127
128
129
130
131
|
# File 'lib/esp/cli.rb', line 123
def unpack(plugin, name = nil)
params = params_with_root('plugin' => plugin, 'name' => name, 'config' => options[:config]).compact
result = Esp::Operations.dispatch(:unpack, params)
respond(result) do
say t('cli.unpack.done', plugin: result[:plugin], output: result[:output])
end
rescue Esp::Operations::InputError, Esp::Mw::Tes3conv::ConvertFailed, Esp::Mw::Tes3conv::NotFound => e
fail_with(e.message)
end
|
#version ⇒ Object
19
20
21
|
# File 'lib/esp/cli.rb', line 19
def version
respond({ version: Esp::VERSION }) { |p| say p[:version] }
end
|