Class: Hone::CLI

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

Overview

Command-line interface for Hone Ruby performance analyzer.

Examples:

Basic usage

hone analyze FILE                    # Static analysis (no profile)
hone analyze FILE --profile FILE     # Correlation mode (prioritized)
hone analyze DIR                     # Analyze directory

Output control

hone analyze FILE --format json      # JSON output
hone analyze FILE --format github    # GitHub Actions annotations
hone analyze FILE --quiet            # Minimal output
hone analyze FILE --no-color         # Disable colors

Filtering

hone analyze FILE --top=10           # Show only top 10 findings
hone analyze FILE --hot-only         # Only HOT findings
hone analyze FILE --show-cold        # Include COLD findings

CI integration

hone analyze FILE --fail-on hot      # Exit 1 for HOT (default)
hone analyze FILE --fail-on warm     # Exit 2 for WARM, 1 for HOT
hone analyze FILE --fail-on any      # Exit 1 for any finding
hone analyze FILE --fail-on none     # Always exit 0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/hone/cli.rb', line 34

def self.exit_on_failure?
  true
end

Instance Method Details

#analyze(path) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/hone/cli.rb', line 117

def analyze(path)
  analyzer = Analyzer.new(
    path,
    profile: options[:profile],
    memory_profile: options[:memory_profile],
    format: options[:format],
    color: options[:color],
    quiet: options[:quiet],
    verbose: options[:verbose],
    top: options[:top],
    hot_only: options[:hot_only],
    show_cold: options[:show_cold],
    fail_on: options[:fail_on],
    diff: options[:diff],
    baseline: options[:baseline],
    rails: options[:rails]
  )

  result = analyzer.run

  puts result.output unless result.output.empty?

  exit result.exit_code
end

#init(component) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/hone/cli.rb', line 157

def init(component)
  case component
  when "harness"
    generator = HarnessGenerator.new(rails: options[:rails])
    generator.generate
  else
    puts "Unknown component: #{component}"
    puts "Available components: harness"
    exit 1
  end
end

#profileObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/hone/cli.rb', line 207

def profile
  unless File.exist?(options[:harness])
    puts "Harness file not found: #{options[:harness]}"
    puts "Run 'hone init harness' to generate a template."
    exit 1
  end

  profiler_opt = (options[:profiler] == "auto") ? nil : options[:profiler].to_sym

  runner = HarnessRunner.new(
    options[:harness],
    profiler: profiler_opt,
    memory: options[:memory],
    warmup: options[:warmup],
    output_dir: options[:output]
  )

  puts "Loading harness from #{options[:harness]}..."
  puts "Warmup: #{options[:warmup]} iterations"
  puts "Profiler: #{profiler_opt || "auto-detect"}"
  puts

  profiles = runner.run

  puts "Profiles generated:"
  puts "  CPU:    #{profiles[:cpu]}"
  puts "  Memory: #{profiles[:memory]}" if profiles[:memory]
  puts

  if options[:analyze]
    puts "Running analysis..."
    invoke :analyze, ["."], profile: profiles[:cpu], memory_profile: profiles[:memory]
  else
    puts "Run analysis with:"
    puts "  hone analyze . --profile #{profiles[:cpu]}"
  end
end

#versionObject



39
40
41
# File 'lib/hone/cli.rb', line 39

def version
  puts "Hone v#{Hone::VERSION}"
end