Class: Slidict::Cli::App

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

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout, renderer: Output::Renderer.new, auth_client: nil, credentials: nil, sleeper: Kernel, slides_command: nil, server: nil, lint_command: nil) ⇒ App

Returns a new instance of App.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/slidict/cli/app.rb', line 9

def initialize(input: $stdin, output: $stdout, renderer: Output::Renderer.new, auth_client: nil,
               credentials: nil, sleeper: Kernel, slides_command: nil, server: nil, lint_command: nil)
  @input = input
  @output = output
  @renderer = renderer
  @auth_client = auth_client
  @credentials = credentials
  @sleeper = sleeper
  @slides_command = slides_command
  @server = server
  @lint_command = lint_command
end

Instance Method Details

#run(argv = []) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/slidict/cli/app.rb', line 22

def run(argv = [])
  options = parse(argv)
  return print_help if options[:help]
  return auth if options[:command] == "auth"
  return slides(options[:args]) if options[:command] == "slides"
  return serve(options[:args]) if options[:command] == "serve"
  return lint(options[:args]) if options[:command] == "lint"

  config = build_config(options)
  return print_available_models(config) if config.llm_enabled? && config.model.nil?

  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 Llm::Client::Error => e
      @output.puts "Error: LLM request failed (#{e.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]
  content = @renderer.render(deck)
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, content)
  @output.puts "Created #{path}"

  return publish_to_slidict(deck, content, options) if options[:publish] || options[:slide_id]

  0
rescue ArgumentError => e
  @output.puts "Error: #{e.message}"
  @output.puts
  print_help
  1
end