Class: Ukiryu::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/config.rb,
lib/ukiryu/config/env_schema.rb,
lib/ukiryu/config/env_provider.rb,
lib/ukiryu/config/type_converter.rb,
lib/ukiryu/config/override_resolver.rb

Overview

Global configuration for Ukiryu Provides unified configuration across CLI, Ruby API, and programmatic interfaces

Configuration priority (highest to lowest):

  1. CLI options (passed at runtime)

  2. Environment variables (UKIRYU_*)

  3. Programmatic configuration (Config.configure)

  4. Default values

Examples:

Configure programmatically

Ukiryu::Config.configure do |config|
  config.timeout = 30
  config.debug = true
  config.format = :json
end

Configure via environment variables

export UKIRYU_TIMEOUT=60
export UKIRYU_DEBUG=true
export UKIRYU_FORMAT=json

Configure via CLI options

ukiryu exec ping host=example.com --format json --timeout 30

Defined Under Namespace

Classes: EnvProvider, EnvSchema, OverrideResolver, TypeConverter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



77
78
79
# File 'lib/ukiryu/config.rb', line 77

def initialize
  @resolver = build_resolver
end

Instance Attribute Details

#resolverObject (readonly)

Returns the value of attribute resolver.



75
76
77
# File 'lib/ukiryu/config.rb', line 75

def resolver
  @resolver
end

Class Method Details

.configure {|config| ... } ⇒ Config

Configure Ukiryu with a block

Yields:

  • (config)

    The configuration instance

Returns:

  • (Config)

    The configuration instance



44
45
46
47
# File 'lib/ukiryu/config.rb', line 44

def configure
  yield instance if block_given?
  instance
end

.instanceObject



35
36
37
38
39
# File 'lib/ukiryu/config.rb', line 35

def instance
  mutex.synchronize do
    @instance ||= new
  end
end

.method_missing(method) ⇒ Object

Delegate to instance



57
58
59
# File 'lib/ukiryu/config.rb', line 57

def method_missing(method, ...)
  instance.send(method, ...)
end

.reset!Object

Reset configuration to defaults



50
51
52
53
54
# File 'lib/ukiryu/config.rb', line 50

def reset!
  mutex.synchronize do
    @instance = new
  end
end

.respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ukiryu/config.rb', line 61

def respond_to_missing?(method, include_private = false)
  instance.respond_to?(method) || super
end

Instance Method Details

#colors_disabled?Boolean

Check if colors are disabled Returns true if use_color is explicitly false or if NO_COLOR is set

Returns:

  • (Boolean)

    true if colors should be disabled



173
174
175
# File 'lib/ukiryu/config.rb', line 173

def colors_disabled?
  use_color == false
end

#debugBoolean

Debug mode flag

Returns:

  • (Boolean)

    true if debug mode is enabled



100
101
102
# File 'lib/ukiryu/config.rb', line 100

def debug
  @resolver.resolve(:debug)
end

#debug=(value) ⇒ Object

Set debug mode

Parameters:

  • value (Boolean)

    debug mode flag



106
107
108
# File 'lib/ukiryu/config.rb', line 106

def debug=(value)
  @resolver.set_programmatic(:debug, value)
end

#dry_runBoolean

Dry run flag

Returns:

  • (Boolean)

    true if dry run is enabled



112
113
114
# File 'lib/ukiryu/config.rb', line 112

def dry_run
  @resolver.resolve(:dry_run)
end

#dry_run=(value) ⇒ Object

Set dry run mode

Parameters:

  • value (Boolean)

    dry run flag



118
119
120
# File 'lib/ukiryu/config.rb', line 118

def dry_run=(value)
  @resolver.set_programmatic(:dry_run, value)
end

#formatSymbol

Output format

Returns:

  • (Symbol)

    output format (:yaml, :json, :table)



124
125
126
# File 'lib/ukiryu/config.rb', line 124

def format
  @resolver.resolve(:format)
end

#format=(value) ⇒ Object

Set output format

Parameters:

  • value (Symbol)

    output format



130
131
132
# File 'lib/ukiryu/config.rb', line 130

def format=(value)
  @resolver.set_programmatic(:format, value)
end

#metricsBoolean

Metrics collection flag

Returns:

  • (Boolean)

    true if metrics should be collected



179
180
181
# File 'lib/ukiryu/config.rb', line 179

def metrics
  @resolver.resolve(:metrics)
end

#metrics=(value) ⇒ Object

Set metrics collection

Parameters:

  • value (Boolean)

    metrics flag



185
186
187
# File 'lib/ukiryu/config.rb', line 185

def metrics=(value)
  @resolver.set_programmatic(:metrics, value)
end

#outputString?

Output file path

Returns:

  • (String, nil)

    output file path, or nil for stdout



136
137
138
# File 'lib/ukiryu/config.rb', line 136

def output
  @resolver.resolve(:output)
end

#output=(value) ⇒ Object

Set output file path

Parameters:

  • value (String)

    output file path



142
143
144
# File 'lib/ukiryu/config.rb', line 142

def output=(value)
  @resolver.set_programmatic(:output, value)
end

#registerString?

Register path

Returns:

  • (String, nil)

    path to tool register



148
149
150
# File 'lib/ukiryu/config.rb', line 148

def register
  @resolver.resolve(:register)
end

#register=(value) ⇒ Object

Set register path

Parameters:

  • value (String)

    path to tool register



154
155
156
# File 'lib/ukiryu/config.rb', line 154

def register=(value)
  @resolver.set_programmatic(:register, value)
end

#reset!Object

Reset configuration to defaults



82
83
84
# File 'lib/ukiryu/config.rb', line 82

def reset!
  @resolver = build_resolver
end

#set_cli_option(key, value) ⇒ Object

Set CLI option (highest priority)

Parameters:

  • key (Symbol)

    option key

  • value (Object)

    option value



204
205
206
# File 'lib/ukiryu/config.rb', line 204

def set_cli_option(key, value)
  @resolver.set_cli(key, value)
end

#shellSymbol?

Shell to use for command execution

Returns:

  • (Symbol, nil)

    shell symbol (:bash, :zsh, :fish, :powershell, :cmd) or nil for auto-detect



191
192
193
# File 'lib/ukiryu/config.rb', line 191

def shell
  @resolver.resolve(:shell)
end

#shell=(value) ⇒ Object

Set shell

Parameters:

  • value (Symbol, String)

    shell symbol or string



197
198
199
# File 'lib/ukiryu/config.rb', line 197

def shell=(value)
  @resolver.set_programmatic(:shell, value&.to_sym)
end

#timeoutInteger?

Execution timeout in seconds

Returns:

  • (Integer, nil)

    timeout in seconds, or nil for no timeout



88
89
90
# File 'lib/ukiryu/config.rb', line 88

def timeout
  @resolver.resolve(:timeout)
end

#timeout=(value) ⇒ Object

Set execution timeout

Parameters:

  • value (Integer)

    timeout in seconds



94
95
96
# File 'lib/ukiryu/config.rb', line 94

def timeout=(value)
  @resolver.set_programmatic(:timeout, value)
end

#to_hHash

Get configuration as hash

Returns:

  • (Hash)

    configuration values



210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/ukiryu/config.rb', line 210

def to_h
  {
    timeout: timeout,
    debug: debug,
    dry_run: dry_run,
    metrics: metrics,
    shell: shell,
    format: format,
    output: output,
    register: register,
    use_color: use_color
  }
end

#use_colorBoolean

Use color in output

Returns:

  • (Boolean)

    true if colors should be used



160
161
162
# File 'lib/ukiryu/config.rb', line 160

def use_color
  @resolver.resolve(:use_color)
end

#use_color=(value) ⇒ Object

Set color usage

Parameters:

  • value (Boolean)

    color usage flag



166
167
168
# File 'lib/ukiryu/config.rb', line 166

def use_color=(value)
  @resolver.set_programmatic(:use_color, value)
end