Class: Vivlio::Starter::CLI::SamovarCommands::PreflightCommand

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/vivlio/starter/cli/samovar/preflight_command.rb

Overview

preflight コマンドの Samovar 実装

Instance Method Summary collapse

Constructor Details

#initialize(input = nil) ⇒ PreflightCommand

Returns a new instance of PreflightCommand.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vivlio/starter/cli/samovar/preflight_command.rb', line 45

def initialize(input = nil, **)
  processed_input = if input
                      normalized = normalize_log_option_tokens(input)
                      if input.respond_to?(:replace) && !input.equal?(normalized)
                        input.replace(normalized)
                        input
                      else
                        normalized
                      end
                    else
                      input
                    end
  super(processed_input, **)
end

Instance Method Details

#callObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/vivlio/starter/cli/samovar/preflight_command.rb', line 60

def call
  if options[:help]
    print_usage
    return 0
  end

  PreProcessCommands::LinkImageValidator.reset!

  # 検証オプションをスレッドローカルに設定(LinkImageValidator が参照)
  setup_verify_options!

  entries = resolve_entries
  if entries.empty? && targets.any?
    Common.log_error('指定した章が catalog.yml に存在しません。preflight を中断します。')
    return 1
  end

  pipeline = BuildCommands::UnifiedBuildPipeline.new(self, entries: entries, mode: :preflight)
  pipeline.run

  # --verify-links 有効時のみ外部 URL チェックを実行
  PreProcessCommands::LinkImageValidator.check_external_urls!
  PreProcessCommands::LinkImageValidator.print_summary

  print_preflight_summary

  PreProcessCommands::LinkImageValidator.any_issues? ? 1 : 0
rescue SystemExit => e
  raise e
rescue StandardError => e
  Common.log_error("Error: #{e.message}")
  1
ensure
  # 前処理で生成した中間 .md ファイルを後始末する
  CleanCommands.execute_clean({})
  Thread.current[:vs_verify_options] = nil
end