Module: CodexNotify::HookConfig
- Extended by:
- ConfigSupport
- Defined in:
- lib/codex_notify/hook_config.rb
Defined Under Namespace
Classes: Args, Error
Constant Summary
collapse
- DEFAULT_ENV_PATH =
ConfigSupport::DEFAULT_ENV_PATH
- DEFAULT_STATE_PATH =
Pathname(File.expand_path('~/.codex-notify-hook/state.json'))
- DEFAULT_MODE =
'normal'
- MODES =
%w[normal debug].freeze
ConfigSupport::DEFAULT_ENV_POLICY, ConfigSupport::ENV_POLICIES, ConfigSupport::REPOSITORY_ALLOWED_KEYS, ConfigSupport::REPOSITORY_CREDENTIAL_PATTERN
Class Method Summary
collapse
add_common_options, apply_destination, eligible_sources, getenv_any, load_env_file, resolve_env_paths, resolve_policy, system_user_name, trusted_sources, warn_if_legacy_tool_source, warn_ignored_repository_values
Class Method Details
.apply_presentation(options, sources, policy:) ⇒ Object
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/codex_notify/hook_config.rb', line 98
def apply_presentation(options, sources, policy:)
eligible = eligible_sources(sources, policy:)
trusted = trusted_sources(sources)
options.user_name ||= eligible.lookup('CODEX_NOTIFY_USER_NAME')&.value || system_user_name
options.title ||= eligible.lookup('CODEX_NOTIFY_TITLE')&.value
options.event_name ||= eligible.lookup('CODEX_HOOK_EVENT')&.value ||
eligible.lookup('CODEX_NOTIFY_HOOK_EVENT')&.value
options.mode ||= eligible.lookup('CODEX_NOTIFY_MODE')&.value || DEFAULT_MODE
options.outbox_dir ||= trusted.lookup('CODEX_NOTIFY_OUTBOX_DIR')&.value
end
|
.build_parser ⇒ Object
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
|
# File 'lib/codex_notify/hook_config.rb', line 42
def build_parser
options = Args.new(
env_file: DEFAULT_ENV_PATH,
env_file_explicit: false,
config_file: nil,
migrate_config: false,
token: nil,
channel: nil,
destination: nil,
user_name: nil,
title: nil,
state_file: DEFAULT_STATE_PATH.to_s,
event_name: nil,
mode: nil,
outbox_dir: nil,
outbox_action: nil,
outbox_id: nil,
token_from_cli: false
)
parser = OptionParser.new do |opts|
opts.banner = 'Usage: codex-notify-hook [options]'
add_common_options(opts, options)
opts.on('--state-file PATH') { |v| options.state_file = v }
opts.on('--event NAME') { |v| options.event_name = v }
opts.on('--mode MODE', MODES) { |v| options.mode = v }
opts.on('--outbox-dir PATH') { |v| options.outbox_dir = v }
end
[parser, options]
end
|
.parse_args(argv = nil, stderr: $stderr, legacy_checkout_root: nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/codex_notify/hook_config.rb', line 74
def parse_args(argv = nil, stderr: $stderr, legacy_checkout_root: nil)
parser, options = build_parser
parser.parse!(argv || [])
return options if options.migrate_config
ConfigDiagnostics.warn_deprecated_cli_token(stderr:) if options.token_from_cli
sources = EnvSourceLoader.new(legacy_checkout_root:, stderr:).load(
path: options.env_file,
explicit: options.env_file_explicit,
config_path: options.config_file
)
policy = resolve_policy(sources, stderr:)
warn_ignored_repository_values(sources, policy:, stderr:)
apply_destination(options, sources, policy:, stderr:)
apply_presentation(options, sources, policy:)
options.outbox_dir ||= "#{options.state_file}.outbox"
raise Error, "mode must be one of: #{MODES.join(', ')}" unless MODES.include?(options.mode)
options
rescue ConfigSupport::Error, EnvSourceLoader::Error, TrustedConfigLoader::Error, DestinationResolver::Error => e
raise Error, e.message
end
|