Class: Explore::Cli::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/explore/cli.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://exploremyprofile.com".freeze
ENVELOPED_JSON_COMMANDS =
[
  "setup claude",
  "whoami",
  "profile inspect",
  "content list",
  "export profile",
  "validate",
  "preview profile",
  "apply",
  "onboarding status",
  "manifest next-actions",
  "notion sync-status",
  "publish preview"
].freeze
DEFAULT_LOGIN_POLL_INTERVAL =
1
DEFAULT_LOGIN_MAX_POLLS =
120

Instance Method Summary collapse

Constructor Details

#initialize(argv:, env:, stdout:, stderr:, stdin: $stdin, client_class: Client, config_store: nil, secret_prompt: nil, browser_launcher: nil, sleeper: nil) ⇒ Runner

Returns a new instance of Runner.



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/explore/cli.rb', line 170

def initialize(argv:, env:, stdout:, stderr:, stdin: $stdin, client_class: Client, config_store: nil, secret_prompt: nil, browser_launcher: nil, sleeper: nil)
  @argv = argv.dup
  @original_argv = argv.dup
  @env = env
  @stdout = stdout
  @stderr = stderr
  @stdin = stdin
  @client_class = client_class
  @config_store = config_store || ConfigStore.new(env:)
  @secret_prompt = secret_prompt
  @browser_launcher = browser_launcher
  @sleeper = sleeper || ->(seconds) { sleep(seconds) }
end

Instance Method Details

#callObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/explore/cli.rb', line 184

def call
  return handle_help_request if help_requested?(argv)

  command = argv.shift
  return emit_version if version_flag?(command)
  raise Error.new(usage, exit_code: 2) if blank_value?(command)

  exit_code = case command
  when "version"
    emit_version
  when "setup"
    if argv.first == "claude"
      argv.shift
      options = parse_setup_claude_options(argv)
      execute_setup_claude(options)
      return 0
    end
    options = parse_options(argv, require_input: false)
    execute_setup(options)
  when "register"
    options = parse_options(argv, require_input: false)
    execute_register(options)
  when "login"
    options = parse_options(argv, require_input: false, include_stored: false)
    (options)
  when "logout"
    options = parse_options(argv, require_input: false, include_stored: false)
    removed = config_store.delete
    emit(output_for_logout(removed, options))
  when "commands"
    options = parse_meta_options(argv)
    emit(options[:json] ? JSON.pretty_generate(CommandCatalog.commands_payload) : CommandCatalog.commands_text)
  when "whoami"
    options = parse_options(argv, require_input: false)
    validate_whoami_scope!(options)
    response = client(options).get("/api/agent/v1/profile", params: scope_params(options))
    emit(output_for_whoami(response, options))
  when "export"
    execute_export(argv)
  when "validate"
    execute_validate(argv)
  when "preview"
    execute_preview(argv)
  when "apply"
    execute_apply(argv)
  when "profile"
    execute_read(argv.shift, "/api/agent/v1/profile")
  when "content"
    subcommand = argv.shift
    return execute_read(subcommand, "/api/agent/v1/content") if subcommand == "list"
    return execute_create_draft if subcommand == "create-draft"
    return execute_propose_update if subcommand == "propose-update"
    raise Error.new(usage, exit_code: 2)
  when "drafts"
    subcommand = argv.shift
    return execute_read(subcommand, "/api/agent/v1/drafts") if subcommand == "list"
    return execute_draft_inspect if subcommand == "inspect"
    return execute_draft_apply if subcommand == "apply"
    return execute_draft_apply_preview if subcommand == "apply-preview"
    return execute_draft_update if subcommand == "update"
    return execute_draft_archive if subcommand == "archive"
    raise Error.new(usage, exit_code: 2)
  when "onboarding"
    execute_read(argv.shift, "/api/agent/v1/onboarding/status")
  when "manifest"
    execute_read(argv.shift, "/api/agent/v1/manifest/next_actions")
  when "notion"
    execute_read(argv.shift, "/api/agent/v1/notion/sync_status")
  when "publish"
    execute_read(argv.shift, "/api/agent/v1/publish/preview")
  else
    raise Error.new(usage, exit_code: 2)
  end

  exit_code || 0
    rescue Error => e
  emit_json_error(e) || begin
    stderr.puts(e.message)
    e.exit_code
  end
rescue OptionParser::ParseError => e
  emit_json_error(Error.new(e.message, exit_code: 2, details: { error_code: "invalid_options" })) || begin
    stderr.puts(e.message)
    2
  end
end