Skip to content

Commit e81b4d8

Browse files
feat(cli): Add TOON output format support
Add support for TOON output format across all CLI formatters: - Add 'toon' as a valid output format - Implement TOON encoding for all resource types - Update base CLI to support TOON format validation - Add toon-ruby dependency to Gemspec - Create comprehensive test coverage for TOON output format This allows users to receive more compact, efficient serialization of CLI output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8d9c3c7 commit e81b4d8

26 files changed

Lines changed: 266 additions & 12 deletions

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PATH
44
exa-ai (0.5.0)
55
faraday (~> 2.0)
66
ld-eventsource (~> 2.0)
7+
toon-ruby (~> 0.1)
78

89
GEM
910
remote: https://rubygems.org/
@@ -57,6 +58,7 @@ GEM
5758
rake (13.3.0)
5859
rexml (3.4.4)
5960
thor (1.4.0)
61+
toon-ruby (0.1.1)
6062
uri (1.0.4)
6163
vcr (6.3.1)
6264
base64

exa.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
2929
# Runtime dependencies
3030
spec.add_dependency "faraday", "~> 2.0"
3131
spec.add_dependency "ld-eventsource", "~> 2.0"
32+
spec.add_dependency "toon-ruby", "~> 0.1"
3233

3334
# Development dependencies
3435
spec.add_development_dependency "minitest", "~> 5.0"

lib/exa/cli/base.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def self.resolve_api_key(flag_value)
1616
end
1717

1818
# Resolve and validate output format
19-
# Valid formats: json, pretty, text
19+
# Valid formats: json, pretty, text, toon
2020
# Defaults to json
2121
def self.resolve_output_format(flag_value)
2222
format = (flag_value || "json").downcase
23-
valid_formats = %w[json pretty text]
23+
valid_formats = %w[json pretty text toon]
2424

2525
return format if valid_formats.include?(format)
2626

@@ -46,6 +46,12 @@ def self.format_output(data, format)
4646
data.to_s
4747
end
4848
end
49+
50+
# Encode data as TOON format
51+
def self.encode_as_toon(data)
52+
require "toon" unless defined?(Toon)
53+
Toon.encode(data)
54+
end
4955
end
5056
end
5157
end

lib/exa/cli/formatters/answer_formatter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def self.format(result, format)
1212
format_pretty(result)
1313
when "text"
1414
format_text(result)
15+
when "toon"
16+
Exa::CLI::Base.encode_as_toon(result.to_h)
1517
else
1618
JSON.pretty_generate(result.to_h)
1719
end

lib/exa/cli/formatters/contents_formatter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def self.format(result, format)
1212
format_pretty(result)
1313
when "text"
1414
format_text(result)
15+
when "toon"
16+
Exa::CLI::Base.encode_as_toon(result.to_h)
1517
else
1618
JSON.pretty_generate(result.to_h)
1719
end

lib/exa/cli/formatters/context_formatter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def self.format(result, format)
1414
format_pretty(result)
1515
when "text"
1616
format_text(result)
17+
when "toon"
18+
Exa::CLI::Base.encode_as_toon(result.to_h)
1719
else
1820
JSON.pretty_generate(result.to_h)
1921
end

lib/exa/cli/formatters/enrichment_formatter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def self.format(enrichment, output_format)
1212
JSON.pretty_generate(enrichment.to_h)
1313
when "text"
1414
format_as_text(enrichment)
15+
when "toon"
16+
Exa::CLI::Base.encode_as_toon(enrichment.to_h)
1517
else
1618
raise ArgumentError, "Unknown output format: #{output_format}"
1719
end
@@ -25,6 +27,8 @@ def self.format_collection(collection, output_format)
2527
JSON.pretty_generate(collection.to_h)
2628
when "text"
2729
format_collection_as_text(collection)
30+
when "toon"
31+
Exa::CLI::Base.encode_as_toon(collection.to_h)
2832
else
2933
raise ArgumentError, "Unknown output format: #{output_format}"
3034
end

lib/exa/cli/formatters/import_formatter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def self.format(import, output_format)
1212
JSON.pretty_generate(import.to_h)
1313
when "text"
1414
format_as_text(import)
15+
when "toon"
16+
Exa::CLI::Base.encode_as_toon(import.to_h)
1517
else
1618
raise ArgumentError, "Unknown output format: #{output_format}"
1719
end
@@ -25,6 +27,8 @@ def self.format_collection(collection, output_format)
2527
JSON.pretty_generate(collection.to_h)
2628
when "text"
2729
format_collection_as_text(collection)
30+
when "toon"
31+
Exa::CLI::Base.encode_as_toon(collection.to_h)
2832
else
2933
raise ArgumentError, "Unknown output format: #{output_format}"
3034
end

lib/exa/cli/formatters/monitor_formatter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def self.format(monitor, output_format)
1212
JSON.pretty_generate(monitor.to_h)
1313
when "text"
1414
format_as_text(monitor)
15+
when "toon"
16+
Exa::CLI::Base.encode_as_toon(monitor.to_h)
1517
else
1618
raise ArgumentError, "Unknown output format: #{output_format}"
1719
end
@@ -25,6 +27,8 @@ def self.format_collection(collection, output_format)
2527
JSON.pretty_generate(collection.to_h)
2628
when "text"
2729
format_collection_as_text(collection)
30+
when "toon"
31+
Exa::CLI::Base.encode_as_toon(collection.to_h)
2832
else
2933
raise ArgumentError, "Unknown output format: #{output_format}"
3034
end

lib/exa/cli/formatters/monitor_run_formatter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def self.format(monitor_run, output_format)
1212
JSON.pretty_generate(monitor_run.to_h)
1313
when "text"
1414
format_as_text(monitor_run)
15+
when "toon"
16+
Exa::CLI::Base.encode_as_toon(monitor_run.to_h)
1517
else
1618
raise ArgumentError, "Unknown output format: #{output_format}"
1719
end
@@ -25,6 +27,8 @@ def self.format_collection(collection, output_format)
2527
JSON.pretty_generate(collection.to_h)
2628
when "text"
2729
format_collection_as_text(collection)
30+
when "toon"
31+
Exa::CLI::Base.encode_as_toon(collection.to_h)
2832
else
2933
raise ArgumentError, "Unknown output format: #{output_format}"
3034
end

0 commit comments

Comments
 (0)