Module: Parabot::CLI

Defined in:
lib/parabot/cli.rb,
lib/parabot/cli/command_router.rb,
lib/parabot/cli/argument_parser.rb

Defined Under Namespace

Modules: Commands Classes: ArgumentParser, CommandRouter

Class Method Summary collapse

Class Method Details

.build_args_with_options(args, options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/parabot/cli.rb', line 49

def self.build_args_with_options(args, options)
  result = args.dup

  # Add global options back to args for dry-cli
  result << "--dry-run" if options[:dry_run]
  result << "--force" if options[:force]
  result += ["--config", options[:config]] if options[:config]
  result += ["--language", options[:language]] if options[:language]
  result += ["--timeout", options[:timeout].to_s] if options[:timeout]
  result += ["--project-root", options[:project_root]] if options[:project_root]

  result
end

.ensure_configuration_loaded(config_file = nil, project_root = nil) ⇒ Object



42
43
44
45
46
47
# File 'lib/parabot/cli.rb', line 42

def self.ensure_configuration_loaded(config_file = nil, project_root = nil)
  return if Configuration.instance_variable_get(:@instance)

  Configuration.load(config_file, project_root)
  LoggingSetup.setup_with_config(Configuration.current)
end

.execute_builtin_command(args) ⇒ Object

Simplified CLI that delegates to separate components This maintains backward compatibility while improving architecture



66
67
68
69
# File 'lib/parabot/cli.rb', line 66

def self.execute_builtin_command(args)
  cli = Dry::CLI.new(Commands)
  cli.call(arguments: args)
end

.start(args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/parabot/cli.rb', line 24

def self.start(args)
  parser = ArgumentParser.new
  router = CommandRouter.new(Commands)
  result = router.route_command(args, parser) # Configuration is already loaded in route_command

  args_with_options =
    case result[:type]
    when :builtin_command
      build_args_with_options(result[:args], result[:options])
    when :custom_command, :message
      build_args_with_options(["message", result[:message]], result[:options])
    when :help
      result[:args]
    end

  execute_builtin_command(args_with_options)
end