Class: Ace::Overseer::CLI::Commands::Prompt

Inherits:
Support::Cli::Command
  • Object
show all
Includes:
Support::Cli::Base
Defined in:
lib/ace/overseer/cli/commands/prompt.rb

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, input: $stdin) ⇒ Prompt

Returns a new instance of Prompt.



11
12
13
14
15
# File 'lib/ace/overseer/cli/commands/prompt.rb', line 11

def initialize(client: nil, input: $stdin)
  super()
  @client = client || Molecules::LabClient.new
  @input = input
end

Instance Method Details

#call(work:, file: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ace/overseer/cli/commands/prompt.rb', line 16

def call(work:, file: nil, **)
  if file
    prompt = File.read(file)
  else
    if @input.respond_to?(:tty?) && @input.tty?
      raise Ace::Support::Cli::Error, "prompt text is required via --file or stdin"
    end
    prompt = @input.read
  end
  raise Ace::Support::Cli::Error, "prompt text must contain non-whitespace characters" if prompt.strip.empty?

  puts @client.call("work", "prompt", work, stdin_data: prompt, json: false)
rescue => error
  raise Ace::Support::Cli::Error.new(error.message)
end