Class: AlgoScaffold::CLI

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

Instance Method Summary collapse

Instance Method Details

#generate(problem_name, url, method_name, *method_args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/algo_scaffold/cli.rb', line 8

def generate(problem_name, url, method_name, *method_args)
  generator = Generator.new(
    problem_name: problem_name,
    url: url,
    method_name: method_name,
    method_args: method_args,
  )

  generator.generate!

  puts "\n✓ Successfully generated files:".green
  puts "  📁 src/#{problem_name}.rb".cyan
  puts "  📁 spec/#{problem_name}_spec.rb".cyan

  puts "\n💡 Next steps:".yellow
  puts "  1. Implement the #{method_name} method in src/#{problem_name}.rb"
  puts "  2. Add test cases in spec/#{problem_name}_spec.rb"
  puts "  3. Run tests with: rspec spec/#{problem_name}_spec.rb"
rescue Generator::ValidationError => e
  puts "❌ #{e.message}".red
  exit 1
end

#listObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/algo_scaffold/cli.rb', line 32

def list
  src_files = Dir.glob("src/*.rb").map { |f| File.basename(f, '.rb') }

  if src_files.empty?
    puts "No algorithm files found.".yellow
    return
  end

  puts "📚 Generated algorithms:".green
  src_files.each do |file|
    spec_exists = File.exist?("spec/#{file}_spec.rb")
    status = spec_exists ? "✓".green : "✗".red
    puts "  #{status} #{file}"
  end
end

#versionObject



49
50
51
# File 'lib/algo_scaffold/cli.rb', line 49

def version
  puts AlgoScaffold::VERSION
end