Class: Slidict::CLI

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

Constant Summary collapse

DEFAULT_OUTPUT =
"slides.md"

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout, renderer: MarkdownRenderer.new) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
# File 'lib/slidict/cli.rb', line 7

def initialize(input: $stdin, output: $stdout, renderer: MarkdownRenderer.new)
  @input = input
  @output = output
  @renderer = renderer
end

Instance Method Details

#run(argv = []) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/slidict/cli.rb', line 13

def run(argv = [])
  options = parse(argv)
  return print_help if options[:help]

  config = build_config(options)
  client = llm_client_for(config)
  return 1 if client && !verify_connection(client)

  deck = Deck.new(
    topic: ask("What would you like to talk about?", options[:topic]),
    duration: ask("How long is the presentation?", options[:duration]),
    audience: ask("Who is the audience?", options[:audience]),
    goal: ask("What should the audience remember or do?", options[:goal]),
    framework: options[:framework]
  )

  if client
    begin
      slides = client.generate_slides(deck)
    rescue LLMClient::Error => error
      @output.puts "Error: LLM request failed (#{error.message})"
      return 1
    end
    deck = Deck.new(
      topic: deck.topic, duration: deck.duration, audience: deck.audience, goal: deck.goal,
      framework: deck.framework, slides: slides
    )
  end

  path = options[:output]
  File.write(path, @renderer.render(deck))
  @output.puts "Created #{path}"
  0
rescue ArgumentError => error
  @output.puts "Error: #{error.message}"
  @output.puts
  print_help
  1
end