Class: Ragdoll::CLI::Config

Inherits:
Thor
  • Object
show all
Defined in:
lib/ragdoll/cli/commands/config.rb

Instance Method Summary collapse

Instance Method Details

#databaseObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/ragdoll/cli/commands/config.rb', line 117

def database
  loader = ConfigurationLoader.new

  unless loader.config_exists?
    puts "No configuration file found. Run 'ragdoll config init' to create one."
    return
  end

  config = YAML.load_file(loader.config_path)
  db_config = config['database_config']

  puts 'Database Configuration:'
  puts "  Adapter: #{db_config['adapter']}"
  puts "  Database: #{db_config['database']}"
  puts "  Auto-migrate: #{db_config['auto_migrate']}"

  if db_config['adapter'] == 'postgresql'
    puts "  Host: #{db_config['host'] || 'localhost'}"
    puts "  Port: #{db_config['port'] || 5432}"
    puts "  Username: #{db_config['username']}"
  end

  begin
    client = StandaloneClient.new
    if client.healthy?
      puts "\nDatabase Status: ✓ Connected"
    else
      puts "\nDatabase Status: ✗ Connection failed"
    end
  rescue StandardError => e
    puts "\nDatabase Status: ✗ Error - #{e.message}"
  end
end

#get(key) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ragdoll/cli/commands/config.rb', line 90

def get(key)
  loader = ConfigurationLoader.new

  unless loader.config_exists?
    puts "No configuration file found. Run 'ragdoll config init' to create one."
    return
  end

  config = YAML.load_file(loader.config_path)

  # Support nested keys with dot notation
  keys = key.split('.')
  value = config
  keys.each do |k|
    value = value[k] if value.is_a?(Hash)
  end

  puts "#{key} = #{value}"
end

#initObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ragdoll/cli/commands/config.rb', line 9

def init
  loader = ConfigurationLoader.new

  if loader.config_exists?
    puts "Configuration file already exists at: #{loader.config_path}"
    if yes?('Overwrite existing configuration?')
      loader.create_default_config
      puts "Configuration file created at: #{loader.config_path}"
    else
      puts 'Configuration unchanged.'
      return
    end
  else
    loader.create_default_config
    puts "Configuration file created at: #{loader.config_path}"
  end

  puts "\nDefault configuration created with PostgreSQL database."
  puts 'You may need to:'
  puts '1. Ensure PostgreSQL is installed and running'
  puts '2. Create the database: createdb ragdoll_development'
  puts '3. Set your API keys in environment variables:'
  puts '   export OPENAI_API_KEY=your_key_here'
  puts "4. Or add them to the config file under 'api_keys' section"
  puts '5. For production, update the database configuration:'
  puts '   ragdoll config set database_config.database ragdoll_production'
  puts "6. Edit #{loader.config_path} to customize settings"
end

#pathObject



111
112
113
114
# File 'lib/ragdoll/cli/commands/config.rb', line 111

def path
  loader = ConfigurationLoader.new
  puts loader.config_path
end

#set(key, value) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ragdoll/cli/commands/config.rb', line 54

def set(key, value)
  loader = ConfigurationLoader.new

  unless loader.config_exists?
    puts "No configuration file found. Run 'ragdoll config init' to create one."
    return
  end

  config = YAML.load_file(loader.config_path)

  # Parse numeric values
  if value.match?(/^\d+$/)
    value = value.to_i
  elsif value.match?(/^\d+\.\d+$/)
    value = value.to_f
  elsif value == 'true'
    value = true
  elsif value == 'false'
    value = false
  end

  # Support nested keys with dot notation
  keys = key.split('.')
  current = config
  keys[0..-2].each do |k|
    current[k] ||= {}
    current = current[k]
  end
  current[keys.last] = value

  File.write(loader.config_path, YAML.dump(config))
  puts "Set #{key} = #{value}"
  puts 'Note: Restart the CLI or reload configuration for changes to take effect.'
end

#showObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ragdoll/cli/commands/config.rb', line 39

def show
  loader = ConfigurationLoader.new

  unless loader.config_exists?
    puts "No configuration file found. Run 'ragdoll config init' to create one."
    return
  end

  config = YAML.load_file(loader.config_path)
  puts "Configuration from: #{loader.config_path}"
  puts
  puts YAML.dump(config)
end