exa-ai 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "exa-ai"
5
5
  require_relative "../lib/exa/cli/search_parser"
6
+ require_relative "../lib/exa/cli/get_contents"
6
7
 
7
8
  VALID_HIGHLIGHTS_VERBOSITY = %w[low medium high].freeze
8
9
 
@@ -13,192 +14,135 @@ def validate_choice(flag, value, allowed)
13
14
  raise ArgumentError, "#{flag} must be one of: #{allowed.join(', ')}"
14
15
  end
15
16
 
16
- # Parse command line arguments
17
+ # Parse command line arguments into the options hash that
18
+ # build_contents_params reads. The contents flags that search and
19
+ # find-similar share go through Exa::CLI::ContentsFlags.parse, so all three
20
+ # commands read them the same way; the loop below reads only the flags that
21
+ # are get-contents' own. A "--" argument that is not in
22
+ # Exa::CLI::GetContents::FLAGS is an unknown option, even when
23
+ # ContentsFlags.parse knows it.
17
24
  def parse_args(args)
18
- urls = []
19
- ids = []
20
- max_age_hours = nil
21
- snapshot_as_of = nil
22
- user_identifier = nil
23
- compliance = nil
24
- highlights = false
25
- highlights_query = nil
26
- highlights_max_characters = nil
27
- highlights_verbosity = nil
28
- text_verbosity = nil
29
- api_key = nil
30
- text = false
31
- text_max_characters = nil
32
- include_html_tags = false
33
- summary = false
34
- summary_query = nil
35
- summary_schema = nil
36
- subpages = nil
37
- subpage_target = []
38
- links = nil
39
- image_links = nil
40
- context = false
41
- context_max_characters = nil
42
- livecrawl_timeout = nil
43
- output_format = nil
25
+ options = {
26
+ urls: [],
27
+ ids: [],
28
+ max_age_hours: nil,
29
+ snapshot_as_of: nil,
30
+ user_identifier: nil,
31
+ compliance: nil,
32
+ highlights: false,
33
+ highlights_query: nil,
34
+ highlights_max_characters: nil,
35
+ highlights_verbosity: nil,
36
+ text_verbosity: nil,
37
+ api_key: nil,
38
+ text: false,
39
+ text_max_characters: nil,
40
+ include_html_tags: false,
41
+ summary: false,
42
+ summary_query: nil,
43
+ summary_schema: nil,
44
+ subpages: nil,
45
+ subpage_target: [],
46
+ links: nil,
47
+ image_links: nil,
48
+ context: false,
49
+ context_max_characters: nil,
50
+ livecrawl_timeout: nil,
51
+ output_format: nil,
52
+ print_request: false,
53
+ strict: false,
54
+ deprecated_flags: []
55
+ }
44
56
 
45
57
  i = 0
46
58
  while i < args.length
47
59
  arg = args[i]
60
+ if arg.start_with?("--")
61
+ entry = Exa::CLI::GetContents::FLAGS.find { |candidate| candidate[:flag] == arg }
62
+ Exa::CLI::Base.reject_unknown_option(arg) unless entry
63
+ options[:deprecated_flags] << entry if entry[:deprecated]
64
+ end
65
+
66
+ next_index = Exa::CLI::ContentsFlags.parse(args, i, options)
67
+ if next_index
68
+ i = next_index
69
+ next
70
+ end
48
71
 
49
72
  case arg
50
73
  when "--api-key"
51
- api_key = args[i + 1]
52
- i += 2
53
- when "--text"
54
- text = true
55
- i += 1
56
- when "--text-max-characters"
57
- text_max_characters = Exa::CLI::Base.parse_integer("--text-max-characters", args[i + 1])
58
- i += 2
59
- when "--include-html-tags"
60
- include_html_tags = true
61
- i += 1
62
- when "--summary"
63
- summary = true
64
- i += 1
65
- when "--summary-query"
66
- summary_query = args[i + 1]
67
- i += 2
68
- when "--summary-schema"
69
- summary_schema = Exa::CLI::Base.parse_json_or_file("--summary-schema", args[i + 1])
70
- i += 2
71
- when "--subpages"
72
- subpages = Exa::CLI::Base.parse_integer("--subpages", args[i + 1])
73
- i += 2
74
- when "--subpage-target"
75
- subpage_target << args[i + 1]
76
- i += 2
77
- when "--links"
78
- links = Exa::CLI::Base.parse_integer("--links", args[i + 1])
79
- i += 2
80
- when "--image-links"
81
- image_links = Exa::CLI::Base.parse_integer("--image-links", args[i + 1])
82
- i += 2
83
- when "--context"
84
- context = true
85
- i += 1
86
- when "--context-max-characters"
87
- context_max_characters = Exa::CLI::Base.parse_integer("--context-max-characters", args[i + 1])
88
- i += 2
89
- when "--livecrawl-timeout"
90
- livecrawl_timeout = Exa::CLI::Base.parse_integer("--livecrawl-timeout", args[i + 1])
74
+ options[:api_key] = Exa::CLI::Base.text_value("--api-key", args[i + 1])
91
75
  i += 2
92
76
  when "--output-format"
93
- output_format = args[i + 1]
77
+ options[:output_format] = Exa::CLI::Base.text_value("--output-format", args[i + 1])
94
78
  i += 2
95
79
  when "--ids"
96
- ids = Exa::CLI::Base.option_value("--ids", args[i + 1]).split(",").map(&:strip)
97
- i += 2
98
- when "--max-age-hours"
99
- max_age_hours = Exa::CLI::Base.parse_integer("--max-age-hours", args[i + 1])
100
- i += 2
101
- when "--snapshot-as-of"
102
- snapshot_as_of = args[i + 1]
80
+ options[:ids] = Exa::CLI::GetContents.split_urls(Exa::CLI::Base.text_value("--ids", args[i + 1]))
103
81
  i += 2
104
82
  when "--user-identifier"
105
- user_identifier = args[i + 1]
83
+ options[:user_identifier] = Exa::CLI::Base.text_value("--user-identifier", args[i + 1])
106
84
  i += 2
107
85
  when "--compliance"
108
- compliance = args[i + 1]
109
- validate_choice("--compliance", compliance, Exa::CLI::SearchParser::VALID_COMPLIANCE)
110
- i += 2
111
- when "--highlights"
112
- highlights = true
113
- i += 1
114
- when "--highlights-query"
115
- highlights_query = args[i + 1]
116
- i += 2
117
- when "--highlights-max-characters"
118
- highlights_max_characters = Exa::CLI::Base.parse_integer("--highlights-max-characters", args[i + 1])
86
+ options[:compliance] = Exa::CLI::Base.text_value("--compliance", args[i + 1])
87
+ validate_choice("--compliance", options[:compliance], Exa::CLI::SearchParser::VALID_COMPLIANCE)
119
88
  i += 2
120
89
  when "--highlights-verbosity"
121
- highlights_verbosity = args[i + 1]
122
- validate_choice("--highlights-verbosity", highlights_verbosity, VALID_HIGHLIGHTS_VERBOSITY)
123
- i += 2
124
- when "--text-verbosity"
125
- text_verbosity = args[i + 1]
126
- validate_choice("--text-verbosity", text_verbosity, Exa::CLI::SearchParser::VALID_TEXT_VERBOSITY)
90
+ options[:highlights_verbosity] = Exa::CLI::Base.text_value("--highlights-verbosity", args[i + 1])
91
+ validate_choice("--highlights-verbosity", options[:highlights_verbosity], VALID_HIGHLIGHTS_VERBOSITY)
127
92
  i += 2
93
+ when "--print-request"
94
+ options[:print_request] = true
95
+ i += 1
96
+ when "--strict"
97
+ options[:strict] = true
98
+ i += 1
128
99
  when "--help", "-h"
129
100
  print_help
130
101
  exit 0
131
102
  else
132
- # First non-flag argument is the URLs (comma-separated or single)
133
- urls = arg.split(",").map(&:strip) if urls.empty?
103
+ # A URL never starts with a dash, so any dash argument left here
104
+ # (one dash or two) is an option this command does not know.
105
+ Exa::CLI::Base.reject_unknown_option(arg) if arg.start_with?("-")
106
+
107
+ # Every non-flag argument adds its URLs to the list. One argument can
108
+ # hold several URLs; split_urls keeps a comma that is part of a URL.
109
+ options[:urls].concat(Exa::CLI::GetContents.split_urls(arg))
134
110
  i += 1
135
111
  end
136
112
  end
137
113
 
138
- {
139
- urls: urls,
140
- ids: ids,
141
- max_age_hours: max_age_hours,
142
- snapshot_as_of: snapshot_as_of,
143
- user_identifier: user_identifier,
144
- compliance: compliance,
145
- highlights: highlights,
146
- highlights_query: highlights_query,
147
- highlights_max_characters: highlights_max_characters,
148
- highlights_verbosity: highlights_verbosity,
149
- text_verbosity: text_verbosity,
150
- api_key: api_key,
151
- text: text,
152
- text_max_characters: text_max_characters,
153
- include_html_tags: include_html_tags,
154
- summary: summary,
155
- summary_query: summary_query,
156
- summary_schema: summary_schema,
157
- subpages: subpages,
158
- subpage_target: subpage_target,
159
- links: links,
160
- image_links: image_links,
161
- context: context,
162
- context_max_characters: context_max_characters,
163
- livecrawl_timeout: livecrawl_timeout,
164
- output_format: output_format
165
- }
114
+ options
166
115
  end
167
116
 
168
- # Build contents parameters from extracted flags
117
+ # Build contents parameters from extracted flags. A sub-option such as
118
+ # --text-max-characters turns its parent on, as ContentsFlags.build does.
169
119
  def build_contents_params(args)
170
120
  params = {}
171
121
 
172
122
  # Text options
173
- if args[:text]
174
- if args[:text_max_characters] || args[:include_html_tags] || args[:text_verbosity]
175
- params[:text] = {}
176
- params[:text][:max_characters] = args[:text_max_characters] if args[:text_max_characters]
177
- params[:text][:include_html_tags] = args[:include_html_tags] if args[:include_html_tags]
178
- params[:text][:verbosity] = args[:text_verbosity] if args[:text_verbosity]
179
- else
180
- params[:text] = true
181
- end
123
+ if args[:text_max_characters] || args[:include_html_tags] || args[:text_verbosity]
124
+ params[:text] = {}
125
+ params[:text][:max_characters] = args[:text_max_characters] if args[:text_max_characters]
126
+ params[:text][:include_html_tags] = args[:include_html_tags] if args[:include_html_tags]
127
+ params[:text][:verbosity] = args[:text_verbosity] if args[:text_verbosity]
128
+ elsif args[:text]
129
+ params[:text] = true
182
130
  end
183
131
 
184
132
  # Summary options
185
- if args[:summary]
186
- if args[:summary_query] || args[:summary_schema]
187
- params[:summary] = {}
188
- params[:summary][:query] = args[:summary_query] if args[:summary_query]
189
- params[:summary][:schema] = args[:summary_schema] if args[:summary_schema]
190
- else
191
- params[:summary] = true
192
- end
133
+ if args[:summary_query] || args[:summary_schema]
134
+ params[:summary] = {}
135
+ params[:summary][:query] = args[:summary_query] if args[:summary_query]
136
+ params[:summary][:schema] = args[:summary_schema] if args[:summary_schema]
137
+ elsif args[:summary]
138
+ params[:summary] = true
193
139
  end
194
140
 
195
141
  # Context options
196
- if args[:context]
197
- if args[:context_max_characters]
198
- params[:context] = { max_characters: args[:context_max_characters] }
199
- else
200
- params[:context] = true
201
- end
142
+ if args[:context_max_characters]
143
+ params[:context] = { max_characters: args[:context_max_characters] }
144
+ elsif args[:context]
145
+ params[:context] = true
202
146
  end
203
147
 
204
148
  # Subpages options
@@ -213,15 +157,13 @@ def build_contents_params(args)
213
157
  end
214
158
 
215
159
  # Highlights options
216
- if args[:highlights]
217
- if args[:highlights_query] || args[:highlights_max_characters] || args[:highlights_verbosity]
218
- params[:highlights] = {}
219
- params[:highlights][:query] = args[:highlights_query] if args[:highlights_query]
220
- params[:highlights][:max_characters] = args[:highlights_max_characters] if args[:highlights_max_characters]
221
- params[:highlights][:verbosity] = args[:highlights_verbosity] if args[:highlights_verbosity]
222
- else
223
- params[:highlights] = true
224
- end
160
+ if args[:highlights_query] || args[:highlights_max_characters] || args[:highlights_verbosity]
161
+ params[:highlights] = {}
162
+ params[:highlights][:query] = args[:highlights_query] if args[:highlights_query]
163
+ params[:highlights][:max_characters] = args[:highlights_max_characters] if args[:highlights_max_characters]
164
+ params[:highlights][:verbosity] = args[:highlights_verbosity] if args[:highlights_verbosity]
165
+ elsif args[:highlights]
166
+ params[:highlights] = true
225
167
  end
226
168
 
227
169
  # Livecrawl and freshness options
@@ -239,13 +181,14 @@ end
239
181
 
240
182
  def print_help
241
183
  puts <<~HELP
242
- Usage: exa-ai get-contents <urls> [options]
184
+ Usage: exa-ai get-contents <url> [<url> ...] [options]
243
185
  exa-ai get-contents --ids ID1,ID2 [options]
244
186
 
245
187
  Retrieve full page contents from URLs or document IDs
246
188
 
247
189
  Arguments:
248
- urls Comma-separated list of URLs (required unless --ids is given)
190
+ url One or more URLs, as separate arguments (required unless --ids is given).
191
+ URL1,URL2 in one argument also works when each URL starts with http:// or https://
249
192
 
250
193
  Options:
251
194
  Text Extraction:
@@ -292,6 +235,11 @@ def print_help
292
235
  General:
293
236
  --api-key KEY Exa API key (or set EXA_API_KEY env var)
294
237
  --output-format FMT Output format: json, pretty, or text (default: json)
238
+ --print-request Write the JSON request body sent to the API to stderr
239
+ (one line); the request is still sent
240
+ --strict Stop with an error instead of a warning when a
241
+ deprecated flag is given; no request is sent
242
+ --flags-json Print every flag this command accepts as JSON and exit
295
243
  --help, -h Show this help message
296
244
 
297
245
  Examples:
@@ -305,9 +253,20 @@ def print_help
305
253
  end
306
254
 
307
255
  begin
256
+ # Print the flag list for wrappers before anything else, so it needs no
257
+ # API key and wins over every other argument.
258
+ if ARGV.include?("--flags-json")
259
+ puts JSON.generate(Exa::CLI::GetContents::FLAGS)
260
+ exit 0
261
+ end
262
+
308
263
  # Parse arguments
309
264
  options = parse_args(ARGV)
310
265
 
266
+ # Warn about deprecated flags, or stop on them with --strict, before the
267
+ # API key is read or a request is sent.
268
+ Exa::CLI::Base.report_deprecated_flags(options[:deprecated_flags], strict: options[:strict])
269
+
311
270
  # Validate that there is something to fetch
312
271
  if options[:urls].empty? && options[:ids].empty?
313
272
  $stderr.puts "Error: URLs argument or --ids required"
@@ -323,7 +282,7 @@ begin
323
282
  output_format = Exa::CLI::Base.resolve_output_format(options[:output_format])
324
283
 
325
284
  # Build client
326
- client = Exa::CLI::Base.build_client(api_key)
285
+ client = Exa::CLI::Base.build_client(api_key, print_request: options[:print_request])
327
286
 
328
287
  # Build request parameters
329
288
  params = build_contents_params(options)
data/exe/exa-ai-search CHANGED
@@ -56,6 +56,11 @@ def print_help
56
56
  General Options:
57
57
  --api-key KEY Exa API key (or set EXA_API_KEY env var)
58
58
  --output-format FMT Output format: json, pretty, or text (default: json)
59
+ --print-request Write the JSON request body sent to the API to stderr
60
+ (one line); the request is still sent
61
+ --strict Stop with an error instead of a warning when a
62
+ deprecated flag is given; no request is sent
63
+ --flags-json Print every flag this command accepts as JSON and exit
59
64
  --help, -h Show this help message
60
65
 
61
66
  Examples:
@@ -71,6 +76,13 @@ end
71
76
 
72
77
  # Main execution
73
78
  begin
79
+ # Print the flag list for wrappers before anything else, so it needs no
80
+ # API key and wins over a query, --help and unknown flags.
81
+ if ARGV.include?("--flags-json")
82
+ puts JSON.generate(Exa::CLI::SearchParser::FLAGS)
83
+ exit 0
84
+ end
85
+
74
86
  # Handle help flag
75
87
  if ARGV.include?("--help") || ARGV.include?("-h")
76
88
  print_help
@@ -80,6 +92,10 @@ begin
80
92
  # Parse command-line arguments
81
93
  args = Exa::CLI::SearchParser.parse(ARGV)
82
94
 
95
+ # Warn about deprecated flags, or stop on them with --strict, before the
96
+ # API key is read or a request is sent.
97
+ Exa::CLI::Base.report_deprecated_flags(args[:deprecated_flags], strict: args[:strict])
98
+
83
99
  # Resolve API key
84
100
  api_key = Exa::CLI::Base.resolve_api_key(args[:api_key])
85
101
 
@@ -87,7 +103,7 @@ begin
87
103
  output_format = Exa::CLI::Base.resolve_output_format(args[:output_format])
88
104
 
89
105
  # Build client
90
- client = Exa::CLI::Base.build_client(api_key)
106
+ client = Exa::CLI::Base.build_client(api_key, print_request: args[:print_request])
91
107
 
92
108
  # Prepare search parameters
93
109
  search_params = {}
@@ -123,6 +139,10 @@ begin
123
139
  $stdout.flush
124
140
  Exa::CLI::Formatters::SearchFormatter.print_warnings(result)
125
141
 
142
+ rescue ArgumentError => e
143
+ # A flag value the parser rejects, such as --type quick, or no query.
144
+ $stderr.puts "Error: #{e.message}"
145
+ exit 1
126
146
  rescue Exa::ConfigurationError => e
127
147
  $stderr.puts "Configuration error: #{e.message}"
128
148
  exit 1
@@ -15,13 +15,13 @@ while args.any?
15
15
  arg = args.shift
16
16
  case arg
17
17
  when "--api-key"
18
- api_key = args.shift
18
+ api_key = Exa::CLI::Base.text_value("--api-key", args.shift)
19
19
  when "--action"
20
- action = args.shift
20
+ action = Exa::CLI::Base.text_value("--action", args.shift)
21
21
  when "--status"
22
- filter[:status] = args.shift
22
+ filter[:status] = Exa::CLI::Base.text_value("--status", args.shift)
23
23
  when "--name"
24
- filter[:name] = args.shift
24
+ filter[:name] = Exa::CLI::Base.text_value("--name", args.shift)
25
25
  when "--metadata"
26
26
  filter[:metadata] = Exa::CLI::Base.parse_json_or_file("--metadata", args.shift)
27
27
  when "--limit"
@@ -29,7 +29,7 @@ while args.any?
29
29
  when "--execute"
30
30
  dry_run = false
31
31
  when "--output-format"
32
- output_format = args.shift
32
+ output_format = Exa::CLI::Base.text_value("--output-format", args.shift)
33
33
  when "--help", "-h"
34
34
  puts <<~HELP
35
35
  Usage: exa-ai search-monitor-batch --action ACTION [filter options] [options]
@@ -59,13 +59,13 @@ while args.any?
59
59
  HELP
60
60
  exit 0
61
61
  else
62
- warn "Unknown option: #{arg}"
62
+ $stderr.puts "Unknown option: #{arg}"
63
63
  exit 1
64
64
  end
65
65
  end
66
66
 
67
67
  unless %w[delete pause unpause].include?(action)
68
- warn "Error: --action must be delete, pause, or unpause. Run with --help for usage."
68
+ $stderr.puts "Error: --action must be delete, pause, or unpause. Run with --help for usage."
69
69
  exit 1
70
70
  end
71
71
 
@@ -75,19 +75,19 @@ begin
75
75
  result = client.search_monitor_batch(action: action, filter: filter, dry_run: dry_run, limit: limit)
76
76
  puts Exa::CLI::Formatters::SearchMonitorFormatter.format(result, output_format)
77
77
  rescue Exa::Unauthorized => e
78
- warn "Authentication failed: #{e.message}"
79
- warn "Please provide a valid API key via --api-key or EXA_API_KEY environment variable"
78
+ $stderr.puts "Authentication failed: #{e.message}"
79
+ $stderr.puts "Please provide a valid API key via --api-key or EXA_API_KEY environment variable"
80
80
  exit 1
81
81
  rescue Exa::ClientError => e
82
- warn "Client error: #{e.message}"
82
+ $stderr.puts "Client error: #{e.message}"
83
83
  exit 1
84
84
  rescue Exa::ServerError => e
85
- warn "Server error: #{e.message}"
85
+ $stderr.puts "Server error: #{e.message}"
86
86
  exit 1
87
87
  rescue Exa::Error => e
88
- warn "Error: #{e.message}"
88
+ $stderr.puts "Error: #{e.message}"
89
89
  exit 1
90
90
  rescue StandardError => e
91
- warn "Unexpected error: #{e.message}"
91
+ $stderr.puts "Unexpected error: #{e.message}"
92
92
  exit 1
93
93
  end
@@ -14,29 +14,29 @@ while args.any?
14
14
  arg = args.shift
15
15
  case arg
16
16
  when "--api-key"
17
- api_key = args.shift
17
+ api_key = Exa::CLI::Base.text_value("--api-key", args.shift)
18
18
  when "--query"
19
- search[:query] = args.shift
19
+ search[:query] = Exa::CLI::Base.text_value("--query", args.shift)
20
20
  when "--num-results"
21
21
  search[:num_results] = Exa::CLI::Base.parse_integer("--num-results", args.shift)
22
22
  when "--include-domains"
23
- search[:include_domains] = Exa::CLI::Base.option_value("--include-domains", args.shift).split(",").map(&:strip)
23
+ search[:include_domains] = Exa::CLI::Base.text_value("--include-domains", args.shift).split(",").map(&:strip)
24
24
  when "--exclude-domains"
25
- search[:exclude_domains] = Exa::CLI::Base.option_value("--exclude-domains", args.shift).split(",").map(&:strip)
25
+ search[:exclude_domains] = Exa::CLI::Base.text_value("--exclude-domains", args.shift).split(",").map(&:strip)
26
26
  when "--webhook-url"
27
- webhook[:url] = args.shift
27
+ webhook[:url] = Exa::CLI::Base.text_value("--webhook-url", args.shift)
28
28
  when "--webhook-events"
29
- webhook[:events] = Exa::CLI::Base.option_value("--webhook-events", args.shift).split(",").map(&:strip)
29
+ webhook[:events] = Exa::CLI::Base.text_value("--webhook-events", args.shift).split(",").map(&:strip)
30
30
  when "--period"
31
- params[:trigger] = { type: "interval", period: args.shift }
31
+ params[:trigger] = { type: "interval", period: Exa::CLI::Base.text_value("--period", args.shift) }
32
32
  when "--name"
33
- params[:name] = args.shift
33
+ params[:name] = Exa::CLI::Base.text_value("--name", args.shift)
34
34
  when "--output-schema"
35
35
  params[:output_schema] = Exa::CLI::Base.parse_json_or_file("--output-schema", args.shift)
36
36
  when "--metadata"
37
37
  params[:metadata] = Exa::CLI::Base.parse_json_or_file("--metadata", args.shift)
38
38
  when "--output-format"
39
- output_format = args.shift
39
+ output_format = Exa::CLI::Base.text_value("--output-format", args.shift)
40
40
  when "--help", "-h"
41
41
  puts <<~HELP
42
42
  Usage: exa-ai search-monitor-create --query TEXT --webhook-url URL [options]
@@ -70,13 +70,13 @@ while args.any?
70
70
  HELP
71
71
  exit 0
72
72
  else
73
- warn "Unknown option: #{arg}"
73
+ $stderr.puts "Unknown option: #{arg}"
74
74
  exit 1
75
75
  end
76
76
  end
77
77
 
78
78
  unless search[:query] && webhook[:url]
79
- warn "Error: --query and --webhook-url are required. Run with --help for usage."
79
+ $stderr.puts "Error: --query and --webhook-url are required. Run with --help for usage."
80
80
  exit 1
81
81
  end
82
82
 
@@ -86,19 +86,19 @@ begin
86
86
  result = client.search_monitor_create(search: search, webhook: webhook, **params)
87
87
  puts Exa::CLI::Formatters::SearchMonitorFormatter.format(result, output_format)
88
88
  rescue Exa::Unauthorized => e
89
- warn "Authentication failed: #{e.message}"
90
- warn "Please provide a valid API key via --api-key or EXA_API_KEY environment variable"
89
+ $stderr.puts "Authentication failed: #{e.message}"
90
+ $stderr.puts "Please provide a valid API key via --api-key or EXA_API_KEY environment variable"
91
91
  exit 1
92
92
  rescue Exa::ClientError => e
93
- warn "Client error: #{e.message}"
93
+ $stderr.puts "Client error: #{e.message}"
94
94
  exit 1
95
95
  rescue Exa::ServerError => e
96
- warn "Server error: #{e.message}"
96
+ $stderr.puts "Server error: #{e.message}"
97
97
  exit 1
98
98
  rescue Exa::Error => e
99
- warn "Error: #{e.message}"
99
+ $stderr.puts "Error: #{e.message}"
100
100
  exit 1
101
101
  rescue StandardError => e
102
- warn "Unexpected error: #{e.message}"
102
+ $stderr.puts "Unexpected error: #{e.message}"
103
103
  exit 1
104
104
  end
@@ -12,9 +12,9 @@ while args.any?
12
12
  arg = args.shift
13
13
  case arg
14
14
  when "--api-key"
15
- api_key = args.shift
15
+ api_key = Exa::CLI::Base.text_value("--api-key", args.shift)
16
16
  when "--output-format"
17
- output_format = args.shift
17
+ output_format = Exa::CLI::Base.text_value("--output-format", args.shift)
18
18
  when "--help", "-h"
19
19
  puts <<~HELP
20
20
  Usage: exa-ai search-monitor-delete ID [options]
@@ -33,7 +33,7 @@ while args.any?
33
33
  exit 0
34
34
  else
35
35
  if arg.start_with?("-") || monitor_id
36
- warn "Unknown option: #{arg}"
36
+ $stderr.puts "Unknown option: #{arg}"
37
37
  exit 1
38
38
  end
39
39
  monitor_id = arg
@@ -41,7 +41,7 @@ while args.any?
41
41
  end
42
42
 
43
43
  unless monitor_id
44
- warn "Error: ID is required. Run with --help for usage."
44
+ $stderr.puts "Error: ID is required. Run with --help for usage."
45
45
  exit 1
46
46
  end
47
47
 
@@ -51,19 +51,19 @@ begin
51
51
  result = client.search_monitor_delete(monitor_id)
52
52
  puts Exa::CLI::Formatters::SearchMonitorFormatter.format(result, output_format)
53
53
  rescue Exa::Unauthorized => e
54
- warn "Authentication failed: #{e.message}"
55
- warn "Please provide a valid API key via --api-key or EXA_API_KEY environment variable"
54
+ $stderr.puts "Authentication failed: #{e.message}"
55
+ $stderr.puts "Please provide a valid API key via --api-key or EXA_API_KEY environment variable"
56
56
  exit 1
57
57
  rescue Exa::ClientError => e
58
- warn "Client error: #{e.message}"
58
+ $stderr.puts "Client error: #{e.message}"
59
59
  exit 1
60
60
  rescue Exa::ServerError => e
61
- warn "Server error: #{e.message}"
61
+ $stderr.puts "Server error: #{e.message}"
62
62
  exit 1
63
63
  rescue Exa::Error => e
64
- warn "Error: #{e.message}"
64
+ $stderr.puts "Error: #{e.message}"
65
65
  exit 1
66
66
  rescue StandardError => e
67
- warn "Unexpected error: #{e.message}"
67
+ $stderr.puts "Unexpected error: #{e.message}"
68
68
  exit 1
69
69
  end