Module: CodexNotify::Config

Extended by:
ConfigSupport
Defined in:
lib/codex_notify/config.rb

Defined Under Namespace

Classes: Args, Error

Constant Summary collapse

DEFAULT_ENV_PATH =
ConfigSupport::DEFAULT_ENV_PATH
DEFAULT_SESSIONS_DIR =
Pathname(File.expand_path('~/.codex/sessions'))
DEFAULT_OUTBOX_DIR =
Pathname(File.expand_path('~/.codex-notify/outbox'))

Constants included from ConfigSupport

CodexNotify::ConfigSupport::DEFAULT_ENV_POLICY, CodexNotify::ConfigSupport::ENV_POLICIES, CodexNotify::ConfigSupport::REPOSITORY_ALLOWED_KEYS, CodexNotify::ConfigSupport::REPOSITORY_CREDENTIAL_PATTERN

Class Method Summary collapse

Methods included from ConfigSupport

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

.build_parserObject



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
# File 'lib/codex_notify/config.rb', line 46

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,
    prompt: nil,
    title: nil,
    include_tools: false,
    throttle_sec: 1.05,
    sessions_dir: DEFAULT_SESSIONS_DIR.to_s,
    session_file: nil,
    poll_sec: 1.0,
    once: false,
    outbox_dir: nil,
    outbox_action: nil,
    outbox_id: nil,
    token_from_cli: false
  )

  parser = OptionParser.new do |opts|
    opts.banner = 'Usage: codex-notify [options]'
    add_common_options(opts, options)
    opts.on('--prompt PROMPT') { |v| options.prompt = v }
    opts.on('--include-tools') { options.include_tools = true }
    opts.on('--throttle-sec FLOAT', Float) { |v| options.throttle_sec = v }
    opts.on('--sessions-dir PATH') { |v| options.sessions_dir = v }
    opts.on('--session-file PATH') { |v| options.session_file = v }
    opts.on('--poll-sec FLOAT', Float) { |v| options.poll_sec = v }
    opts.on('--once') { options.once = true }
    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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/codex_notify/config.rb', line 86

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:)

  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.prompt ||= eligible.lookup('CODEX_PROMPT')&.value
  options.outbox_dir ||= trusted.lookup('CODEX_NOTIFY_OUTBOX_DIR')&.value || DEFAULT_OUTBOX_DIR.to_s
  options
rescue ConfigSupport::Error, EnvSourceLoader::Error, TrustedConfigLoader::Error, DestinationResolver::Error => e
  raise Error, e.message
end