Class: Slidict::Cli::App

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

Constant Summary collapse

QUESTIONS =

Keyed by the same symbols as the parsed CLI options (options, etc.), so a missing answer's question text can be looked up directly by questions_for.

{
  topic: "What would you like to talk about?",
  duration: "How long is the presentation?",
  audience: "Who is the audience?",
  goal: "What should the audience remember or do?"
}.freeze

Constants included from Options

Options::FAILURE, Options::MISSING, Options::SUCCESS

Instance Method Summary collapse

Methods included from Options

included

Instance Method Details

#run(argv = []) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
113
114
115
116
# File 'lib/slidict/cli/app.rb', line 62

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"
  return list_methods if options[:command] == "list-methods"
  return show_method(options[:args]) if options[:command] == "show-method"
  return init if options[:command] == "init"

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

  client = llm_client_for(config)
  return FAILURE if client && !verify_connection(client)

  questions = questions_for(client, options)
  deck = Deck.new(
    topic: ask(questions[:topic], options[:topic]),
    duration: ask(questions[:duration], options[:duration]),
    audience: ask(questions[:audience], options[:audience]),
    goal: ask(questions[:goal], options[:goal]),
    framework: options[:framework],
    presentation_method: options[:presentation_method]
  )

  if client
    begin
      slides = client.generate_slides(deck, language: options[:language])
    rescue Llm::Client::Error => e
      @output.puts "Error: LLM request failed (#{e.message})"
      return FAILURE
    end
    deck = Deck.new(
      topic: deck.topic, duration: deck.duration, audience: deck.audience, goal: deck.goal,
      framework: deck.framework, slides: slides, presentation_method: deck.presentation_method
    )
  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]

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