Module: Vivlio::Starter::CLI

Defined in:
lib/vivlio/starter/cli/new.rb,
lib/vivlio/starter/cli/pdf.rb,
lib/vivlio/starter/cli/toc.rb,
lib/vivlio/starter/cli/epub.rb,
lib/vivlio/starter/cli/lint.rb,
lib/vivlio/starter/cli/build.rb,
lib/vivlio/starter/cli/clean.rb,
lib/vivlio/starter/cli/cover.rb,
lib/vivlio/starter/cli/index.rb,
lib/vivlio/starter/cli/common.rb,
lib/vivlio/starter/cli/create.rb,
lib/vivlio/starter/cli/delete.rb,
lib/vivlio/starter/cli/doctor.rb,
lib/vivlio/starter/cli/doctor.rb,
lib/vivlio/starter/cli/import.rb,
lib/vivlio/starter/cli/rename.rb,
lib/vivlio/starter/cli/resize.rb,
lib/vivlio/starter/cli/convert.rb,
lib/vivlio/starter/cli/entries.rb,
lib/vivlio/starter/cli/metrics.rb,
lib/vivlio/starter/cli/samovar.rb,
lib/vivlio/starter/cli/startup.rb,
lib/vivlio/starter/cli/renumber.rb,
lib/vivlio/starter/cli/pre_process.rb,
lib/vivlio/starter/cli/prism_lines.rb,
lib/vivlio/starter/cli/vivliostyle.rb,
lib/vivlio/starter/cli/font_manager.rb,
lib/vivlio/starter/cli/post_process.rb,
lib/vivlio/starter/cli/metrics/cache.rb,
lib/vivlio/starter/cli/build/pipeline.rb,
lib/vivlio/starter/cli/lint/tokenizer.rb,
lib/vivlio/starter/cli/metrics/runner.rb,
lib/vivlio/starter/cli/token_resolver.rb,
lib/vivlio/starter/cli/build/utilities.rb,
lib/vivlio/starter/cli/build/build_lock.rb,
lib/vivlio/starter/cli/build/pdf_merger.rb,
lib/vivlio/starter/cli/metrics/analyzer.rb,
lib/vivlio/starter/cli/build/pdf_builder.rb,
lib/vivlio/starter/cli/lint/dict_manager.rb,
lib/vivlio/starter/cli/metrics/formatter.rb,
lib/vivlio/starter/cli/build/epub_builder.rb,
lib/vivlio/starter/cli/lint/spell_checker.rb,
lib/vivlio/starter/cli/textlint_formatter.rb,
lib/vivlio/starter/cli/build/pdf_finalizer.rb,
lib/vivlio/starter/cli/build/toc_generator.rb,
lib/vivlio/starter/cli/index/yomi_inferrer.rb,
lib/vivlio/starter/cli/samovar/new_command.rb,
lib/vivlio/starter/cli/samovar/pdf_command.rb,
lib/vivlio/starter/cli/build/catalog_loader.rb,
lib/vivlio/starter/cli/build/chapter_config.rb,
lib/vivlio/starter/cli/build/nombre_stamper.rb,
lib/vivlio/starter/cli/build/output_helpers.rb,
lib/vivlio/starter/cli/index/scoring_engine.rb,
lib/vivlio/starter/cli/metrics/live_display.rb,
lib/vivlio/starter/cli/samovar/help_command.rb,
lib/vivlio/starter/cli/samovar/lint_command.rb,
lib/vivlio/starter/cli/samovar/open_command.rb,
lib/vivlio/starter/cli/samovar/root_command.rb,
lib/vivlio/starter/cli/build/catalog_updater.rb,
lib/vivlio/starter/cli/build/image_optimizer.rb,
lib/vivlio/starter/cli/build/section_builder.rb,
lib/vivlio/starter/cli/import/yaml_processor.rb,
lib/vivlio/starter/cli/metrics/config_loader.rb,
lib/vivlio/starter/cli/samovar/build_command.rb,
lib/vivlio/starter/cli/samovar/clean_command.rb,
lib/vivlio/starter/cli/samovar/cover_command.rb,
lib/vivlio/starter/cli/samovar/index_command.rb,
lib/vivlio/starter/cli/import/image_processor.rb,
lib/vivlio/starter/cli/metrics/catalog_loader.rb,
lib/vivlio/starter/cli/metrics/chapter_parser.rb,
lib/vivlio/starter/cli/samovar/create_command.rb,
lib/vivlio/starter/cli/samovar/delete_command.rb,
lib/vivlio/starter/cli/samovar/doctor_command.rb,
lib/vivlio/starter/cli/samovar/import_command.rb,
lib/vivlio/starter/cli/samovar/rename_command.rb,
lib/vivlio/starter/cli/samovar/resize_command.rb,
lib/vivlio/starter/cli/build/outline_extractor.rb,
lib/vivlio/starter/cli/metrics/parallel_runner.rb,
lib/vivlio/starter/cli/pre_process/css_updater.rb,
lib/vivlio/starter/cli/pre_process/data_render.rb,
lib/vivlio/starter/cli/samovar/metrics_command.rb,
lib/vivlio/starter/cli/index/hierarchical_index.rb,
lib/vivlio/starter/cli/post_process/html_parser.rb,
lib/vivlio/starter/cli/import/markdown_converter.rb,
lib/vivlio/starter/cli/index/index_match_scanner.rb,
lib/vivlio/starter/cli/samovar/preflight_command.rb,
lib/vivlio/starter/cli/build/part_title_generator.rb,
lib/vivlio/starter/cli/index/review_queue_manager.rb,
lib/vivlio/starter/cli/index/unified_page_builder.rb,
lib/vivlio/starter/cli/post_process/html_replacer.rb,
lib/vivlio/starter/cli/pre_process/markdown_utils.rb,
lib/vivlio/starter/cli/build/backlink_deduplicator.rb,
lib/vivlio/starter/cli/index/unified_index_manager.rb,
lib/vivlio/starter/cli/index/unified_terms_manager.rb,
lib/vivlio/starter/cli/pre_process/image_generator.rb,
lib/vivlio/starter/cli/build/page_mapping_extractor.rb,
lib/vivlio/starter/cli/post_process/section_wrapper.rb,
lib/vivlio/starter/cli/post_process/heading_processor.rb,
lib/vivlio/starter/cli/index/index_candidate_extractor.rb,
lib/vivlio/starter/cli/index/review_markdown_generator.rb,
lib/vivlio/starter/cli/post_process/footnote_converter.rb,
lib/vivlio/starter/cli/post_process/body_class_injector.rb,
lib/vivlio/starter/cli/pre_process/link_image_validator.rb,
lib/vivlio/starter/cli/pre_process/markdown_transformer.rb,
lib/vivlio/starter/cli/pre_process/theme_image_resolver.rb,
lib/vivlio/starter/cli/build/backlink_dedup_orchestrator.rb,
lib/vivlio/starter/cli/pre_process/frontmatter_generator.rb,
lib/vivlio/starter/cli/pre_process/image_path_normalizer.rb,
lib/vivlio/starter/cli/pre_process/markdown_preprocessor.rb,
lib/vivlio/starter/cli/pre_process/data_render/singularize.rb,
lib/vivlio/starter/cli/pre_process/cross_reference_processor.rb,
lib/vivlio/starter/cli/pre_process/data_render/template_compiler.rb,
lib/vivlio/starter/cli/pre_process/data_render/query_stream_parser.rb

Defined Under Namespace

Modules: Build, BuildCommands, CleanCommands, Common, ConvertCommands, CoverCommands, CreateCommands, DeleteCommands, DoctorCommands, EntriesCommands, EpubCommands, FontManager, Import, ImportCommands, IndexCommands, Lint, LintCommands, Metrics, MetricsCommands, NewCommands, PdfCommands, PostProcessCommands, PreProcessCommands, PrismLinesCommands, RenameCommands, RenumberCommands, ResizeCommands, SamovarCommands, TocCommands, TokenResolver, VivliostyleCommands Classes: MarkdownResolver, MetricsRunner, RenameCommandExecutor, ReviewMarkdownGenerator, ReviewQueueManager, StatBuilder, TablePrinter, TextlintFormatter, TotalsCalculator, UnifiedIndexManager, UnifiedTermsManager

Constant Summary collapse

TextMetricsCommands =

後方互換: 旧 TextMetricsCommands 定数を維持

MetricsCommands
IndexCandidateExtractor =

IndexCommands モジュール内のクラスへのエイリアス

IndexCommands::IndexCandidateExtractor
IndexMatchScanner =
IndexCommands::IndexMatchScanner
UnifiedPageBuilder =
IndexCommands::UnifiedPageBuilder
YomiInferrer =
IndexCommands::YomiInferrer

Class Method Summary collapse

Class Method Details

.handle_interruptObject

Ctrl+C(SIGINT)受信時のハンドラ。既存の ensure ブロックでの一時ファイルクリーンアップが走った後、UNIX 規約(128 + SIGINT=2)で終了する。



36
37
38
39
# File 'lib/vivlio/starter/cli/startup.rb', line 36

def handle_interrupt
  warn "\n⚠️  処理が中断されました(Ctrl+C)"
  130
end

.handle_signal(error) ⇒ Object

SIGTERM 等のシグナル受信時のハンドラ。ensure による後片付けが走った後、128 + signo で終了する。



43
44
45
46
# File 'lib/vivlio/starter/cli/startup.rb', line 43

def handle_signal(error)
  warn "\n⚠️  処理が中断されました(#{error.message}"
  128 + (Signal.list[error.signm.sub(/\ASIG/, '')] || 15)
end

.handle_unexpected_error(error) ⇒ Object

想定外の Exception 受信時のハンドラ。デバッグ用にはスタックトレースを出すが、通常はメッセージのみ表示。



50
51
52
53
54
# File 'lib/vivlio/starter/cli/startup.rb', line 50

def handle_unexpected_error(error)
  warn "#{error.class}: #{error.message}"
  warn error.backtrace.join("\n") if ENV['VS_DEBUG']
  1
end


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vivlio/starter/cli/startup.rb', line 56

def print_usage_for_invalid_input(error)
  command = error.command

  warn error.message

  Vivlio::Starter::CLI::Common.log_warn('代わりに --help を表示します。') if defined?(Vivlio::Starter::CLI::Common)

  if command.respond_to?(:print_usage)
    command.print_usage
  else
    Vivlio::Starter::CLI::SamovarCommands::RootCommand.new(['--help']).print_usage
  end
rescue StandardError => e
  warn "#{e.class}: #{e.message}"
  warn e.backtrace.join("\n") if ENV['VS_DEBUG']
end

.start(argv) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vivlio/starter/cli/startup.rb', line 14

def start(argv)
  args = Array(argv).dup

  command = Vivlio::Starter::CLI::SamovarCommands::RootCommand.parse(args)
  result = command.call
  result.is_a?(Integer) ? result : 0
rescue Samovar::InvalidInputError => e
  print_usage_for_invalid_input(e)
  0
rescue SystemExit => e
  e.status
rescue Interrupt
  handle_interrupt
rescue SignalException => e
  handle_signal(e)
rescue Exception => e
  handle_unexpected_error(e)
end