Sha256: 34237e6f9a9475832e0a20b8ca38a119a0bf5abfaae1cbd253b4b007c4c36665
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true require 'optparse' module OmniAI # Used when interacting with the suite from the command line interface (CLI). # # Usage: # # cli = OmniAI::CLI.new # cli.parse class CLI ChatArgs = Struct.new(:provider, :model, :temperature) # @param in [IO] a stream # @param out [IO] a stream # @param provider [String] a provider def initialize(stdin: $stdin, stdout: $stdout, provider: 'openai') @stdin = stdin @stdout = stdout @provider = provider @args = {} end def parse(argv = ARGV) parser.order!(argv) command = argv.shift return if command.nil? case command when 'chat' then ChatHandler.handle!(stdin: @stdin, stdout: @stdout, provider: @provider, argv:) else raise Error, "unsupported command=#{command.inspect}" end end private # @return [OptionParser] def parser OptionParser.new do |options| options.banner = 'usage: omniai [options] <command> [<args>]' options.on('-h', '--help', 'help') do @stdout.puts(options) exit end options.on('-v', '--version', 'version') do @stdout.puts(VERSION) exit end options.on('-p', '--provider=PROVIDER', 'provider (default="openai")') do |provider| @provider = provider end options.separator <<~COMMANDS commands: chat COMMANDS end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
omniai-1.4.2 | lib/omniai/cli.rb |
omniai-1.4.1 | lib/omniai/cli.rb |
omniai-1.4.0 | lib/omniai/cli.rb |