Class: Seo::CLI::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/seo/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(args = ARGV, **opts) ⇒ Object



26
27
28
29
30
31
# File 'lib/seo/cli.rb', line 26

def self.start(args = ARGV, **opts)
  pastel = Pastel.new
  $stdout.puts pastel.bright_magenta(LOGO)
  $stdout.puts pastel.bright_magenta("  AI-powered SEO analysis") + "\n\n"
  super
end

Instance Method Details

#check(file = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/seo/cli.rb', line 39

def check(file = nil)
  files = file ? [file] : Scanner.new(config).scan
  if files.empty?
    puts pastel.yellow("No template files found. Check your .seo.yml config.")
    return
  end

  puts pastel.cyan("Analysing #{files.length} file(s)...")

  if options[:format] == "terminal"
    terminal = Output::Terminal.new
    results = Analyser.new(provider: provider).analyse(files) { |r| terminal.render_result(r) }
    terminal.render_summary(results)
  else
    results = Analyser.new(provider: provider).analyse(files)
    puts Output::Reporter.new.render(results, format: options[:format])
  end
end

#fix(file) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/seo/cli.rb', line 59

def fix(file)
  abort(pastel.red("File not found: #{file}")) unless File.exist?(file)

  puts pastel.cyan("Analysing #{file}...")
  result = Analyser.new(provider: provider).fix(file)

  unless result&.fixed_content
    puts pastel.green("No fixes suggested for #{file}")
    return
  end

  Output::Terminal.new.render_diff(result)

  prompt = TTY::Prompt.new
  if prompt.yes?("Apply these changes to #{file}?")
    File.write(file, result.fixed_content)
    puts pastel.green("✓ Changes applied to #{file}")
  else
    puts pastel.yellow("Changes not applied.")
  end
end

#initObject



115
116
117
118
119
120
121
122
# File 'lib/seo/cli.rb', line 115

def init
  if File.exist?(".seo.yml")
    puts pastel.yellow(".seo.yml already exists.")
    return
  end
  Seo::CLI::Config.write_default
  puts pastel.green("✓ Created .seo.yml — edit it to configure which files to scan.")
end

#reportObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/seo/cli.rb', line 84

def report
  files = Scanner.new(config).scan
  if files.empty?
    puts pastel.yellow("No template files found.")
    return
  end

  if options[:format] == "pdf" && options[:output].nil?
    abort pastel.red("--output is required for PDF format. Example: nerima report --format pdf --output seo-report.pdf")
  end

  puts pastel.cyan("Scanning #{files.length} files...")
  done = 0
  results = Analyser.new(provider: provider).analyse(files) do |r|
    done += 1
    puts pastel.dim("  [#{done}/#{files.length}] #{File.basename(r.file)}")
  end
  Output::Terminal.new.render_summary(results)

  if options[:output]
    if options[:format] == "pdf"
      Output::Reporter.new.render_pdf(results, output_path: options[:output])
    else
      fmt = options[:format] == "terminal" ? "html" : options[:format]
      File.write(options[:output], Output::Reporter.new.render(results, format: fmt))
    end
    puts pastel.green("✓ Report written to #{options[:output]}")
  end
end