Class: Esp::CLI::Refs
- Inherits:
-
Thor
- Object
- Thor
- Esp::CLI::Refs
- Includes:
- Support
- Defined in:
- lib/esp/cli/refs.rb
Constant Summary collapse
- MASTERS =
%w[Morrowind Tribunal Bloodmoon].freeze
Class Method Summary collapse
-
.data_candidates ⇒ Object
Detection of the vanilla Data Files directory now lives on Esp::Mw::DataFiles so ‘esp install –to-data-files` can reuse it.
- .default_data ⇒ Object
- .exit_on_failure? ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.data_candidates ⇒ Object
Detection of the vanilla Data Files directory now lives on Esp::Mw::DataFiles so ‘esp install –to-data-files` can reuse it. Refs keeps the names for back-compat with anything that imported them directly.
16 |
# File 'lib/esp/cli/refs.rb', line 16 def self.data_candidates = Esp::Mw::DataFiles.candidates |
.default_data ⇒ Object
17 |
# File 'lib/esp/cli/refs.rb', line 17 def self.default_data = Esp::Mw::DataFiles.default |
.exit_on_failure? ⇒ Boolean
19 |
# File 'lib/esp/cli/refs.rb', line 19 def self.exit_on_failure? = true |
Instance Method Details
#find(query = nil) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/esp/cli/refs.rb', line 69 def find(query = nil) fail_with(t('refs.find.usage')) unless any_filter?(query) idx = require_index! criteria = { query: query, type: [:type], like: [:like], exact: [:exact] } rows = idx.find(**criteria, limit: [:limit]) total = idx.count_matching(**criteria) [:show] ? respond_show(idx, rows, total) : respond_match(rows, total) end |
#index ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/esp/cli/refs.rb', line 52 def index idx = Esp::Mw::ReferenceIndex.new(source_dir: resolved_references_dir) n = idx.rebuild! respond({ indexed: n, db_path: idx.db_path, source_dir: idx.source_dir }) do say t('refs.index.indexing', dir: idx.source_dir, db: idx.db_path) say t('refs.index.indexed', count: n) end rescue RuntimeError => e fail_with(e.) end |
#unpack ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/esp/cli/refs.rb', line 29 def unpack data = [:data] || ENV['MORROWIND_DATA'] || self.class.default_data out = resolved_references_dir FileUtils.mkdir_p(out) unpacked = [] skipped = [] MASTERS.each do |name| src = File.join(data, "#{name}.esm") if File.exist?(src) dst = File.join(out, "#{name}.esm.json") Esp::Mw::Tes3conv.convert(src, dst) unpacked << { name: name, source: src, output: dst } else skipped << { name: name, source: src, reason: 'not found' } end end respond({ unpacked: unpacked, skipped: skipped, references_dir: out }) do unpacked.each { |u| say t('refs.unpack.done', name: u[:name], output: u[:output]) } skipped.each { |s| say t('refs.unpack.skip', source: s[:source], reason: s[:reason]) } end end |