Module: VivlioStarter::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/units.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/guards.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/masking.rb,
lib/vivlio_starter/cli/metrics.rb,
lib/vivlio_starter/cli/samovar.rb,
lib/vivlio_starter/cli/spinner.rb,
lib/vivlio_starter/cli/startup.rb,
lib/vivlio_starter/cli/upgrade.rb,
lib/vivlio_starter/cli/renumber.rb,
lib/vivlio_starter/cli/config_keys.rb,
lib/vivlio_starter/cli/pre_process.rb,
lib/vivlio_starter/cli/prism_lines.rb,
lib/vivlio_starter/cli/theme_color.rb,
lib/vivlio_starter/cli/vivliostyle.rb,
lib/vivlio_starter/cli/font_manager.rb,
lib/vivlio_starter/cli/index_markup.rb,
lib/vivlio_starter/cli/post_process.rb,
lib/vivlio_starter/cli/build/targets.rb,
lib/vivlio_starter/cli/metrics/cache.rb,
lib/vivlio_starter/cli/scaffold_lock.rb,
lib/vivlio_starter/cli/build/pipeline.rb,
lib/vivlio_starter/cli/chapter_rename.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/epub_flow.rb,
lib/vivlio_starter/cli/build/qpdf_json.rb,
lib/vivlio_starter/cli/build/utilities.rb,
lib/vivlio_starter/cli/index/term_line.rb,
lib/vivlio_starter/cli/build/build_lock.rb,
lib/vivlio_starter/cli/build/pdf_merger.rb,
lib/vivlio_starter/cli/code_line_blocks.rb,
lib/vivlio_starter/cli/metrics/analyzer.rb,
lib/vivlio_starter/cli/build/pdf_builder.rb,
lib/vivlio_starter/cli/guards/base_check.rb,
lib/vivlio_starter/cli/guards/node_check.rb,
lib/vivlio_starter/cli/heading_segmenter.rb,
lib/vivlio_starter/cli/index/term_spread.rb,
lib/vivlio_starter/cli/lint/dict_manager.rb,
lib/vivlio_starter/cli/metrics/formatter.rb,
lib/vivlio_starter/cli/build/direct_build.rb,
lib/vivlio_starter/cli/build/epub_builder.rb,
lib/vivlio_starter/cli/build/qpdf_overlay.rb,
lib/vivlio_starter/cli/index/term_pattern.rb,
lib/vivlio_starter/cli/index/term_ranking.rb,
lib/vivlio_starter/cli/lint/spell_checker.rb,
lib/vivlio_starter/cli/samovar/vs_command.rb,
lib/vivlio_starter/cli/techbook/processor.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/index_library.rb,
lib/vivlio_starter/cli/index/yomi_inferrer.rb,
lib/vivlio_starter/cli/lint/notation_guard.rb,
lib/vivlio_starter/cli/metrics/consistency.rb,
lib/vivlio_starter/cli/metrics/readability.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/cmyk_converter.rb,
lib/vivlio_starter/cli/build/nombre_stamper.rb,
lib/vivlio_starter/cli/build/output_helpers.rb,
lib/vivlio_starter/cli/build/print_geometry.rb,
lib/vivlio_starter/cli/doctor/tool_upgrader.rb,
lib/vivlio_starter/cli/guards/relaxed_check.rb,
lib/vivlio_starter/cli/index/main_reference.rb,
lib/vivlio_starter/cli/index/scoring_engine.rb,
lib/vivlio_starter/cli/index/yomi_overrides.rb,
lib/vivlio_starter/cli/metrics/kanji_levels.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/index/heading_outline.rb,
lib/vivlio_starter/cli/metrics/config_loader.rb,
lib/vivlio_starter/cli/metrics/content_words.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/doctor/config_salvager.rb,
lib/vivlio_starter/cli/import/image_processor.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/build/print_pdf_builder.rb,
lib/vivlio_starter/cli/guards/code_fence_check.rb,
lib/vivlio_starter/cli/guards/images_dir_check.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/samovar/upgrade_command.rb,
lib/vivlio_starter/cli/techbook/emoji_replacer.rb,
lib/vivlio_starter/cli/build/crop_marks_overlay.rb,
lib/vivlio_starter/cli/build/math_text_renderer.rb,
lib/vivlio_starter/cli/guards/container_scanner.rb,
lib/vivlio_starter/cli/guards/orphan_file_check.rb,
lib/vivlio_starter/cli/image_filename_sanitizer.rb,
lib/vivlio_starter/cli/import/verbatim_restorer.rb,
lib/vivlio_starter/cli/index/hierarchical_index.rb,
lib/vivlio_starter/cli/metrics/sentence_endings.rb,
lib/vivlio_starter/cli/post_process/html_parser.rb,
lib/vivlio_starter/cli/build/rotate_table_images.rb,
lib/vivlio_starter/cli/guards/catalog_file_check.rb,
lib/vivlio_starter/cli/guards/contents_dir_check.rb,
lib/vivlio_starter/cli/guards/pdf_artifact_check.rb,
lib/vivlio_starter/cli/guards/project_root_check.rb,
lib/vivlio_starter/cli/import/markdown_converter.rb,
lib/vivlio_starter/cli/import/pagebreak_restorer.rb,
lib/vivlio_starter/cli/import/sideimage_restorer.rb,
lib/vivlio_starter/cli/index/code_block_stripper.rb,
lib/vivlio_starter/cli/index/index_match_scanner.rb,
lib/vivlio_starter/cli/index/index_plan_reporter.rb,
lib/vivlio_starter/cli/pre_process/talk_registry.rb,
lib/vivlio_starter/cli/samovar/preflight_command.rb,
lib/vivlio_starter/cli/build/part_title_generator.rb,
lib/vivlio_starter/cli/index/index_size_estimator.rb,
lib/vivlio_starter/cli/index/review_queue_manager.rb,
lib/vivlio_starter/cli/index/unified_page_builder.rb,
lib/vivlio_starter/cli/metrics/sentence_collector.rb,
lib/vivlio_starter/cli/post_process/html_replacer.rb,
lib/vivlio_starter/cli/pre_process/issue_registry.rb,
lib/vivlio_starter/cli/pre_process/markdown_utils.rb,
lib/vivlio_starter/cli/pre_process/qr_transformer.rb,
lib/vivlio_starter/cli/build/backlink_deduplicator.rb,
lib/vivlio_starter/cli/guards/chapter_target_check.rb,
lib/vivlio_starter/cli/guards/image_filename_check.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/pre_process/table_converter.rb,
lib/vivlio_starter/cli/pre_process/theme_validator.rb,
lib/vivlio_starter/cli/build/heading_image_composer.rb,
lib/vivlio_starter/cli/build/pdf_page_map_extractor.rb,
lib/vivlio_starter/cli/guards/catalog_entries_check.rb,
lib/vivlio_starter/cli/guards/config_validity_check.rb,
lib/vivlio_starter/cli/guards/container_class_check.rb,
lib/vivlio_starter/cli/guards/container_fence_check.rb,
lib/vivlio_starter/cli/post_process/section_wrapper.rb,
lib/vivlio_starter/cli/pre_process/math_transformer.rb,
lib/vivlio_starter/cli/pre_process/mermaid_renderer.rb,
lib/vivlio_starter/cli/pre_process/book_settings_css.rb,
lib/vivlio_starter/cli/pre_process/svg_font_embedder.rb,
lib/vivlio_starter/cli/index/main_reference_suggester.rb,
lib/vivlio_starter/cli/post_process/heading_processor.rb,
lib/vivlio_starter/cli/post_process/replacement_rules.rb,
lib/vivlio_starter/cli/build/vivliostyle_config_writer.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/pre_process/data_image_resolver.rb,
lib/vivlio_starter/cli/pre_process/mermaid_transformer.rb,
lib/vivlio_starter/cli/samovar/option_token_normalizer.rb,
lib/vivlio_starter/cli/techbook/variable_font_injector.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/showcase_svg_builder.rb,
lib/vivlio_starter/cli/pre_process/showcase_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/generated_asset_cache.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/talk_avatar_generator.rb,
lib/vivlio_starter/cli/post_process/page_break_normalizer.rb,
lib/vivlio_starter/cli/pre_process/data_render/singularize.rb,
lib/vivlio_starter/cli/post_process/terminal_block_converter.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, ChapterRename, CleanCommands, CodeLineBlocks, Common, ConfigKeys, ConvertCommands, CoverCommands, CreateCommands, DeleteCommands, DoctorCommands, EntriesCommands, EpubCommands, FontManager, Guards, HeadingSegmenter, ImageFilenameSanitizer, Import, ImportCommands, IndexCommands, IndexMarkup, Lint, LintCommands, Masking, Metrics, MetricsCommands, NewCommands, PdfCommands, PostProcessCommands, PreProcessCommands, PrismLinesCommands, RenameCommands, RenumberCommands, ResizeCommands, SamovarCommands, ScaffoldLock, Techbook, ThemeColor, TocCommands, TokenResolver, Units, UpgradeCommands, VivliostyleCommands Classes: RenameCommandExecutor, ReviewMarkdownGenerator, ReviewQueueManager, Spinner, TextlintFormatter, UnifiedIndexManager, UnifiedTermsManager
Constant Summary collapse
- TextMetricsCommands =
後方互換: 旧 TextMetricsCommands 定数を維持
MetricsCommands- IndexCandidateExtractor =
IndexCommands モジュール内のクラスへのエイリアス
IndexCommands::IndexCandidateExtractor
- IndexMatchScanner =
IndexCommands::IndexMatchScanner
- CodeBlockStripper =
IndexCommands::CodeBlockStripper
- UnifiedPageBuilder =
IndexCommands::UnifiedPageBuilder
- YomiInferrer =
IndexCommands::YomiInferrer
Class Method Summary collapse
-
.handle_interrupt ⇒ Object
Ctrl+C(SIGINT)受信時のハンドラ。 既存の ensure ブロックでの一時ファイルクリーンアップが走った後、 UNIX 規約(128 + SIGINT=2)で終了する。.
-
.handle_signal(error) ⇒ Object
SIGTERM 等のシグナル受信時のハンドラ。 ensure による後片付けが走った後、128 + signo で終了する。.
-
.handle_unexpected_error(error) ⇒ Object
想定外の Exception 受信時のハンドラ。 デバッグ用にはスタックトレースを出すが、通常はメッセージのみ表示。.
- .print_usage_for_invalid_input(error) ⇒ Object
- .start(argv) ⇒ Object
Class Method Details
.handle_interrupt ⇒ Object
Ctrl+C(SIGINT)受信時のハンドラ。 既存の ensure ブロックでの一時ファイルクリーンアップが走った後、 UNIX 規約(128 + SIGINT=2)で終了する。
40 41 42 43 |
# File 'lib/vivlio_starter/cli/startup.rb', line 40 def handle_interrupt warn "\n🟡 処理が中断されました(Ctrl+C)" 130 end |
.handle_signal(error) ⇒ Object
SIGTERM 等のシグナル受信時のハンドラ。 ensure による後片付けが走った後、128 + signo で終了する。
47 48 49 50 |
# File 'lib/vivlio_starter/cli/startup.rb', line 47 def handle_signal(error) warn "\n🟡 処理が中断されました(#{error.})" 128 + (Signal.list[error.signm.sub(/\ASIG/, '')] || 15) end |
.handle_unexpected_error(error) ⇒ Object
想定外の Exception 受信時のハンドラ。 デバッグ用にはスタックトレースを出すが、通常はメッセージのみ表示。
54 55 56 57 58 |
# File 'lib/vivlio_starter/cli/startup.rb', line 54 def handle_unexpected_error(error) warn "🔴 #{error.class}: #{error.}" warn error.backtrace.join("\n") if ENV['VS_DEBUG'] 1 end |
.print_usage_for_invalid_input(error) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vivlio_starter/cli/startup.rb', line 60 def print_usage_for_invalid_input(error) command = error.command warn error. VivlioStarter::CLI::Common.log_warn('代わりに --help を表示します。') if defined?(VivlioStarter::CLI::Common) # `vs hogehoge` のような未知のコマンドは、RootCommand の nested が既定の help を # 選ぶため error.command が HelpCommand になる。この場合に help 自身の usage # (`help [-h/--help]`)を見せても手がかりにならないので、`vs --help` と同じ # 主要コマンド一覧を出す。既知コマンドのオプション誤りは、そのコマンドの # 使い方を見せたいので従来どおり print_usage を呼ぶ。 if command.is_a?(VivlioStarter::CLI::SamovarCommands::HelpCommand) command.call elsif command.respond_to?(:print_usage) command.print_usage else VivlioStarter::CLI::SamovarCommands::RootCommand.new(['--help']).print_usage end rescue StandardError => e warn "🔴 #{e.class}: #{e.}" warn e.backtrace.join("\n") if ENV['VS_DEBUG'] end |
.start(argv) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vivlio_starter/cli/startup.rb', line 13 def start(argv) args = Array(argv).dup command = VivlioStarter::CLI::SamovarCommands::RootCommand.parse(args) # ログレベルはここで 1 回だけ確定する。解析より前の出力(未知コマンドのエラー等)は # 既定レベルで出す——解析に失敗した入力の --log 指定を尊重する必要はない。 Common.apply_log_level!(command) result = command.call result.is_a?(Integer) ? result : 0 rescue Samovar::InvalidInputError => e print_usage_for_invalid_input(e) # 無効入力(未知のコマンド・オプション)は POSIX 慣習に従い非 0 で終了する。 # シェルスクリプトや CI からタイプミスを検知できるようにする(契約テスト CL-02) 1 rescue SystemExit => e e.status rescue Interrupt handle_interrupt rescue SignalException => e handle_signal(e) rescue Exception => e handle_unexpected_error(e) end |