Class: Rubino::CLI::ConfigCommand

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

Overview

Subcommands for managing configuration

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rubino/cli/config_command.rb', line 13

def self.exit_on_failure?
  true
end

.redact(value, key: nil) ⇒ Object

Deep DISPLAY masking for config values (#187): a secret-named key’s value renders as *** (Util::SecretsMask — the same heuristic approval prompts use), hashes/arrays are walked, and plain strings are scanned for inline ‘Bearer …`-style credentials. Display-only — the file and the live configuration keep the real values. Empty/nil values pass through unmasked so a *** never fakes a value that isn’t set.



71
72
73
74
75
76
77
78
79
# File 'lib/rubino/cli/config_command.rb', line 71

def self.redact(value, key: nil)
  case value
  when Hash  then value.to_h { |k, v| [k, redact(v, key: k)] }
  when Array then value.map { |v| redact(v, key: key) }
  when String
    value.empty? ? value : Util::SecretsMask.mask_value(value, key: key)
  else value
  end
end

.render_get(key, ui:) ⇒ Object

ONE get rendering for both surfaces (#187): this CLI verb and the in-chat ‘/config get` (Commands::Executor). Resolves against the effective config (file merged over defaults), the same source `show` and the running agent use, so default-valued keys are returned instead of falsely reported “not found” (issue #36). A scalar intermediate node (e.g. descending into a String) has no #dig; treat such a path as “not found” rather than crashing. Secret-named keys render masked.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubino/cli/config_command.rb', line 29

def self.render_get(key, ui:)
  value =
    begin
      Rubino.configuration.dig(*key.split("."))
    rescue TypeError
      nil
    end
  if value.nil?
    ui.warning("Key '#{key}' not found")
  else
    ui.info("#{key} = #{redact(value, key: key.split(".").last)}")
  end
end

.render_show(ui:) ⇒ Object

ONE full-config rendering for both surfaces (#187): this CLI verb and the in-chat ‘/config show` — with secret-named keys masked, which the clear-text dump never did (api_key landed verbatim in the scrollback).



61
62
63
# File 'lib/rubino/cli/config_command.rb', line 61

def self.render_show(ui:)
  ui.info(redact(Rubino.configuration.raw).to_yaml)
end

Instance Method Details

#get(key) ⇒ Object



18
19
20
# File 'lib/rubino/cli/config_command.rb', line 18

def get(key)
  self.class.render_get(key, ui: Rubino.ui)
end

#pathObject



82
83
84
# File 'lib/rubino/cli/config_command.rb', line 82

def path
  Rubino.ui.info(config_path)
end

#set(key, value) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/rubino/cli/config_command.rb', line 44

def set(key, value)
  writer = Config::Writer.new(config_path: config_path)
  writer.set(key, value)
  Rubino.ui.success("#{key} = #{value}")
rescue ConfigurationError => e
  Rubino.ui.error(e.message)
  exit(1)
end

#showObject



54
55
56
# File 'lib/rubino/cli/config_command.rb', line 54

def show
  self.class.render_show(ui: Rubino.ui)
end