Skip to content

Commit

Permalink
Create "tabular-json" CLI command.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jan 6, 2016
1 parent 50c00e6 commit 5008deb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/rdf/tabular/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,21 @@ class Format < RDF::Format
def self.detect(sample)
!!sample.match(/^(?:(?:\w )+,(?:\w ))$/)
end

##
# Hash of CLI commands appropriate for this format
# @return [Hash{Symbol => Lambda(Array, Hash)}]
def self.cli_commands
{
:"tabular-json" => ->(argv, opts) do
raise ArgumentError, "Outputting Tabular JSON only allowed when input format is tabular." unless opts[:format] == :tabular
out = opts[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
RDF::CLI.parse(argv, opts) do |reader|
out.puts reader.to_json
end
end
}
end
end
end

0 comments on commit 5008deb

Please sign in to comment.