Class: Langfuse::CLI::Commands::ConfigCommand

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/langfuse/cli/commands/config.rb', line 10

def self.exit_on_failure?
  true
end

Instance Method Details

#listObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/langfuse/cli/commands/config.rb', line 134

def list
  config_file = File.expand_path('~/.langfuse/config.yml')

  unless File.exist?(config_file)
    puts "No configuration file found at #{config_file}"
    puts "Run 'langfuse config setup' to create one."
    return
  end

  require 'yaml'
  config_data = YAML.load_file(config_file)
  profiles = config_data['profiles'] || {}

  if profiles.empty?
    puts "No profiles configured."
    puts "Run 'langfuse config setup' to create one."
    return
  end

  puts "\nConfigured Profiles:"
  puts "─" * 50

  profiles.each do |name, profile_config|
    puts "\n#{name}:"
    puts "  Host:       #{profile_config['host']}"
    puts "  Public Key: #{mask_key(profile_config['public_key'])}"
  end

  puts "\n─" * 50
end

#set(profile) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/langfuse/cli/commands/config.rb', line 106

def set(profile)
  prompt = TTY::Prompt.new

  config = Config.new(
    public_key: options[:public_key],
    secret_key: options[:secret_key],
    host: options[:host]
  )

  config.save(profile)
  prompt.ok("Configuration saved for profile: #{profile}")
end

#setupObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/langfuse/cli/commands/config.rb', line 36

def setup
  prompt = TTY::Prompt.new

  # Check for environment variables for non-interactive mode
  project_name = ENV['LANGFUSE_PROJECT_NAME']
  public_key = ENV['LANGFUSE_PUBLIC_KEY']
  secret_key = ENV['LANGFUSE_SECRET_KEY']
  host = ENV['LANGFUSE_HOST'] || 'https://cloud.langfuse.com'
  profile_name = ENV['LANGFUSE_PROFILE'] || 'default'

  # Determine if we're in non-interactive mode
  non_interactive = !public_key.nil? && !secret_key.nil?

  if non_interactive
    puts "🔑 Running in non-interactive mode (using environment variables)\n\n"
  else
    puts "\n🔑 Langfuse CLI Configuration Setup\n\n"
  end

  # Prompt for missing values in interactive mode
  unless non_interactive
    project_name ||= prompt.ask('Enter your Langfuse project name:', required: false)

    # Show URL hint if project name was provided
    if project_name && !project_name.empty?
      settings_url = "#{host}/project/#{project_name}/settings"
      prompt.say("💡 Visit: #{settings_url}")
      prompt.say("   (to get your API keys)\n")
    end

    public_key = prompt.ask('Enter your Langfuse public key:', required: true)
    secret_key = prompt.mask('Enter your Langfuse secret key:', required: true)
    host = prompt.ask('Enter host:', default: 'https://cloud.langfuse.com')
    profile_name = prompt.ask('Save as profile name:', default: 'default')
  end

  # Test connection
  begin
    config = Config.new(
      public_key: public_key,
      secret_key: secret_key,
      host: host
    )

    client = Client.new(config)
    client.list_traces(limit: 1)
    prompt.ok('Testing connection... Success!')

    # Save configuration
    config.save(profile_name)
    prompt.ok("Configuration saved to ~/.langfuse/config.yml")
    puts "\nYou're all set! Try: langfuse traces list"
  rescue Client::TimeoutError => e
    prompt.error("Connection test failed: #{e.message}")
    prompt.error("The host '#{host}' may be incorrect or unreachable.")
    exit 1
  rescue Client::AuthenticationError => e
    prompt.error("Connection test failed: #{e.message}")
    prompt.error("Please check your credentials and try again.")
    exit 1
  rescue Client::APIError => e
    prompt.error("Connection test failed: #{e.message}")
    exit 1
  end
end

#show(profile = 'default') ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/langfuse/cli/commands/config.rb', line 120

def show(profile = 'default')
  config = Config.new(profile: profile)

  puts "\nConfiguration for profile: #{profile}"
  puts "─" * 50
  puts "Host:         #{config.host}"
  puts "Public Key:   #{mask_key(config.public_key)}"
  puts "Secret Key:   #{mask_key(config.secret_key)}"
  puts "Output Format: #{config.output_format}"
  puts "Page Limit:   #{config.page_limit}"
  puts "─" * 50
end