Class: VivlioStarter::CLI::SamovarCommands::IndexAutoCommand

Inherits:
VsCommand
  • Object
show all
Defined in:
lib/vivlio_starter/cli/samovar/index_command.rb

Overview

index:auto コマンド - 全自動索引候補抽出

Constant Summary

Constants included from OptionTokenNormalizer

OptionTokenNormalizer::BARE_VALUE_DEFAULTS

Instance Method Summary collapse

Methods included from OptionTokenNormalizer

#initialize, prepended

Instance Method Details

#callObject



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
# File 'lib/vivlio_starter/cli/samovar/index_command.rb', line 121

def call
  return print_usage if options[:help]

  # 前提条件の検証(ProjectRoot ◎ / CatalogFile ◎ / CatalogEntries ○ / ContentsDir ◎)
  guard_failure = Guards.precheck(
    Guards::ProjectRootCheck.new,
    Guards::CatalogFileCheck.new,
    Guards::RelaxedCheck.new(Guards::CatalogEntriesCheck.new),
    Guards::ContentsDirCheck.new
  )
  return guard_failure if guard_failure

  ENV['VERBOSE'] = '1' if options[:verbose]

  # auto_discovery 設定を確認(未設定 nil は true 扱い、false のみ無効化)
  unless Common::CONFIG.index.auto_discovery != false
    Common.log_info('index.auto_discovery: false のため、自動候補抽出は無効です')
    Common.log_info('手動マークアップ [用語|読み] のみが索引に反映されます')
    Common.log_info('自動抽出を有効にするには book.yml で auto_discovery: true を設定してください')
    return 0
  end

  chapters = IndexCommands.resolve_chapters(files || [])

  manager = UnifiedIndexManager.new
  manager.auto_process!(chapters)
  0
rescue SystemExit => e
  raise e
rescue StandardError => e
  Common.log_error("index:auto 実行中にエラー: #{e.message}")
  Common.log_error(e.backtrace.first(5).join("\n")) if ENV['VERBOSE']
  1
end