Skip to content

Commit 4a4eadb

Browse files
committed
Allow CLI commands to define arguments, and use in rdf binary.
1 parent 5f94cee commit 4a4eadb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

bin/rdf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ options = RDF::CLI.options do
1111
self.on('-V', '--version', 'Display the RDF.rb version and exit.') do
1212
puts RDF::VERSION; exit
1313
end
14+
15+
ARGV.select {|a| RDF::CLI.commands.include?(a)}.each do |cmd|
16+
# Load command-specific options
17+
Array(RDF::CLI::COMMANDS[cmd.to_sym][:options]).each do |cli_opt|
18+
on_args = cli_opt.on || []
19+
on_args << cli_opt.description if cli_opt.description
20+
self.on(*on_args) do |arg|
21+
self.options[cli_opt.symbol] = cli_opt.call(arg)
22+
end
23+
end
24+
end
1425
end
1526

1627
abort options.banner if ARGV.empty? && !options.options[:evaluate]

lib/rdf/cli.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def self.commands
409409
# @option options [String] description
410410
# @option options [String] help string to display for help
411411
# @option options [Boolean] parse parse input files in to Repository, or not.
412+
# @option options [Array<RDF::CLI::Option>] options specific to this command
412413
# @yield argv, opts
413414
# @yieldparam [Array<String>] argv
414415
# @yieldparam [Hash] opts
@@ -422,7 +423,7 @@ def self.add_command(command, options = {}, &block)
422423
# @return [Array<String>] list of available formats
423424
def self.formats(reader: false, writer: false)
424425
f = RDF::Format.sort_by(&:to_sym).each.
425-
select {|f| (reader ? f.reader : (writer ? f.writer : true))}.
426+
select {|f| (reader ? f.reader : (writer ? f.writer : (f.reader || f.writer)))}.
426427
inject({}) do |memo, reader|
427428
memo.merge(reader.to_sym => reader.name)
428429
end

0 commit comments

Comments
 (0)