Class: VivlioStarter::CLI::SamovarCommands::ResizeCommand

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

Overview

resize コマンドの Samovar 実装

Constant Summary

Constants included from OptionTokenNormalizer

OptionTokenNormalizer::BARE_VALUE_DEFAULTS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptionTokenNormalizer

#initialize, prepended

Class Method Details

.preset_help(label, preset_name, note: nil) ⇒ Object

プリセットの説明を WEBP_PRESETS から組む。

数値をヘルプに書き写してはならない。 プリセットを動かしたときに黙って 食い違う——--high の上限は 2026-08-17 に 2000 → 2048 へ変えたばかりで、 そのとき原稿の 2 箇所も追いかけて直す必要があった。ここは正典を 1 つに保つ。



39
40
41
42
43
# File 'lib/vivlio_starter/cli/samovar/resize_command.rb', line 39

def self.preset_help(label, preset_name, note: nil)
  preset = ResizeCommands::WEBP_PRESETS.fetch(preset_name)
  parts = ["quality=#{preset[:quality]}", "最大 #{preset[:max_px]}px", note].compact
  "#{label}#{parts.join(' / ')}"
end

Instance Method Details

#callObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vivlio_starter/cli/samovar/resize_command.rb', line 56

def call
  # --help が未定義だと位置引数 dir に「--help」が落ちてしまう(契約テスト CL-01 で検出)
  if options[:help]
    print_usage
    return 0
  end

  # 前提条件の検証(ProjectRoot ◎ / ImagesDir ◎)
  # 既定の images/ 以外を対象にする場合(vs resize <dir>)は ImagesDir を検証しない
  checks = [Guards::ProjectRootCheck.new]
  checks << Guards::ImagesDirCheck.new if resolve_dir == Common::IMAGES_DIR
  guard_failure = Guards.precheck(*checks)
  return guard_failure if guard_failure

  # --medium は既定と同じだが、受け付ける。3 つのプリセットが原稿の表に並んでいるのに
  # 「標準だけはオプションで書けない」のは著者を戸惑わせる(実際に問われた)。
  preset = if options[:high]
             '高精細'
           elsif options[:low]
             '軽量'
           else
             '標準'
           end
  report_result(ResizeCommands.execute_resize_with_preset(preset, resolve_dir, merged_options))
  0
end