Class: AiCli::CLI
- Inherits:
-
Thor
- Object
- Thor
- AiCli::CLI
- Defined in:
- lib/aicli/cli.rb
Constant Summary collapse
- KNOWN_COMMANDS =
%w[config chat update help version].freeze
Class Method Summary collapse
- .exit_on_failure? ⇒ Boolean
- .invoke_prompt(prompt_text, silent: false) ⇒ Object
- .start(given_args = ARGV, config = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
9 10 11 |
# File 'lib/aicli/cli.rb', line 9 def self.exit_on_failure? true end |
.invoke_prompt(prompt_text, silent: false) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aicli/cli.rb', line 47 def self.invoke_prompt(prompt_text, silent: false) Helpers::I18n.load_from_config! Prompt.run(use_prompt: prompt_text, silent_mode: silent) rescue Interrupt puts Helpers::I18n.t('Goodbye!') exit 0 rescue Helpers::KnownError, StandardError => e puts "\n#{Helpers::Theme.pastel.red('✖')} #{e.}" Helpers::Error.handle_cli_error(e) exit 1 end |
.start(given_args = ARGV, config = {}) ⇒ 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 |
# File 'lib/aicli/cli.rb', line 13 def self.start(given_args = ARGV, config = {}) args = given_args.dup silent = args.delete('--silent') || args.delete('-s') version_flag = args.delete('--version') || args.delete('-v') help_flag = args.delete('--help') || args.delete('-h') if version_flag puts AiCli::VERSION return end if help_flag && (args.empty? || !KNOWN_COMMANDS.include?(args.first)) new.help return end prompt_from_flag = nil if (idx = args.index('-p') || args.index('--prompt')) prompt_from_flag = args[idx + 1] args.slice!(idx, 2) end first = args.first unless first.nil? || KNOWN_COMMANDS.include?(first) prompt_text = prompt_from_flag || args.join(' ') invoke_prompt(prompt_text, silent: !silent.nil?) return end thor_args = silent && first == 'chat' ? ['--silent'] + args : args super(thor_args, config) end |
Instance Method Details
#chat ⇒ Object
66 67 68 69 |
# File 'lib/aicli/cli.rb', line 66 def chat Helpers::I18n.load_from_config! Commands::Chat.run end |
#config(mode = nil, *key_values) ⇒ Object
60 61 62 63 |
# File 'lib/aicli/cli.rb', line 60 def config(mode = nil, *key_values) Helpers::I18n.load_from_config! Commands::Config.run(mode, *key_values) end |