Class: Agentic::CLI::ConfigCommands

Inherits:
Thor
  • Object
show all
Defined in:
lib/agentic/cli.rb

Overview

Configuration commands

Constant Summary collapse

CONFIG_FILE_NAME =
".agentic.yml"
USER_CONFIG_PATH =
File.join(Dir.home, CONFIG_FILE_NAME)
PROJECT_CONFIG_PATH =
File.join(Dir.pwd, CONFIG_FILE_NAME)

Instance Method Summary collapse

Instance Method Details

#get(key) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/agentic/cli.rb', line 428

def get(key)
  config = active_config
  value = config[key]

  if value
    value_str = case value
    when true then UI.colorize("true", :green)
    when false then UI.colorize("false", :red)
    when String then "\"#{value}\""
    else value.to_s
    end

    puts UI.box(
      "Configuration Value",
      "#{UI.colorize(key, :blue)}: #{value_str}",
      padding: [1, 2, 1, 2],
      style: {border: {fg: :green}}
    )
  else
    puts UI.box(
      "Error",
      "Key '#{UI.colorize(key, :yellow)}' not found in configuration",
      padding: [1, 2, 1, 2],
      style: {border: {fg: :red}}
    )
    exit 1
  end
end

#initObject



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/agentic/cli.rb', line 494

def init
  path = options[:global] ? USER_CONFIG_PATH : PROJECT_CONFIG_PATH

  if File.exist?(path)
    puts UI.box(
      "Configuration Exists",
      "Configuration already exists at #{UI.colorize(path, :blue)}",
      padding: [1, 2, 1, 2],
      style: {border: {fg: :yellow}}
    )
    return
  end

  config = {
    "model" => "gpt-4o-mini",
    "log_level" => "info"
    # Add other default configuration options here
  }

  save_config(path, config)

  # Format the config for display
  config_str = format_config(config)

  puts UI.box(
    "Configuration Initialized",
    "Created configuration at #{UI.colorize(path, :blue)}\n\n#{config_str}",
    padding: [1, 2, 1, 2],
    style: {border: {fg: :green}}
  )
end

#listObject



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/agentic/cli.rb', line 390

def list
  user_config = load_config(USER_CONFIG_PATH)
  project_config = load_config(PROJECT_CONFIG_PATH)

  # Format user config
  user_config_str = "User configuration (#{USER_CONFIG_PATH}):\n"
  user_config_str += format_config(user_config)

  # Format project config
  project_config_str = "Project configuration (#{PROJECT_CONFIG_PATH}):\n"
  project_config_str += format_config(project_config)

  # Format active config
  active_config_str = "Active configuration:\n"
  active_config_str += format_config(active_config)

  # Format environment variables
  env_vars_str = "Environment variables:\n"
  token_status = ENV["OPENAI_ACCESS_TOKEN"] ?
                UI.colorize("[SET]", :green) :
                UI.colorize("[NOT SET]", :red)
  env_vars_str += "  OPENAI_ACCESS_TOKEN: #{token_status}"

  # Display in a box
  config_info = [
    user_config_str,
    "",
    project_config_str,
    "",
    active_config_str,
    "",
    env_vars_str
  ].join("\n")

  puts UI.box("Configuration", config_info, padding: [1, 2, 1, 2], style: {border: {fg: :blue}})
end

#set(key_value) ⇒ Object



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/agentic/cli.rb', line 460

def set(key_value)
  key, value = key_value.split("=", 2)

  unless value
    puts "Error: Invalid format. Use KEY=VALUE"
    exit 1
  end

  path = options[:global] ? USER_CONFIG_PATH : PROJECT_CONFIG_PATH
  config = load_config(path) || {}

  # Convert string values to appropriate types
  value = case value.downcase
  when "true" then true
  when "false" then false
  when /^\d+$/ then value.to_i
  when /^\d+\.\d+$/ then value.to_f
  else value
  end

  config[key] = value
  save_config(path, config)

  puts UI.box(
    "Configuration Updated",
    "Set #{UI.colorize(key, :blue)} to #{UI.colorize(value.to_s, :green)} in #{path}",
    padding: [1, 2, 1, 2],
    style: {border: {fg: :green}}
  )
end