@@ -162,6 +162,7 @@ def to_hash
162162 # * `lambda` code run to execute command.
163163 # * `filter` Option values that must match for command to be used
164164 # * `control` Used to indicate how (if) command is displayed
165+ # * `repository` Use this repository, if set
165166 # * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
166167 # * `option_use`: A hash of option symbol to option usage, used for overriding the default status of an option for this command.
167168 # @return [Hash{Symbol => Hash{Symbol => Object}}]
@@ -493,6 +494,9 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
493494 raise ArgumentError , "Incompatible command #{ c } used with option #{ opt } =#{ options [ opt ] } "
494495 end
495496 end
497+
498+ # The command may specify a repository instance to use
499+ options [ :repository ] ||= COMMANDS [ c . to_sym ] [ :repository ]
496500 end
497501
498502 # Hacks for specific options
@@ -501,9 +505,12 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
501505 options [ :format ] = options [ :format ] . to_sym if options [ :format ]
502506 options [ :output_format ] = options [ :output_format ] . to_sym if options [ :output_format ]
503507
504- @repository = options [ :ordered ] ?
505- [ ] . extend ( RDF ::Enumerable , RDF ::Queryable ) :
506- RDF ::Repository . new
508+ # Allow repository to be set via option.
509+ @repository = options . fetch ( :repository ) {
510+ options [ :ordered ] ?
511+ [ ] . extend ( RDF ::Enumerable , RDF ::Queryable ) :
512+ RDF ::Repository . new
513+ }
507514
508515 # Parse input files if any command requires it
509516 if cmds . any? { |c | COMMANDS [ c . to_sym ] [ :parse ] }
@@ -518,7 +525,11 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
518525
519526 # Run each command in sequence
520527 cmds . each do |command |
521- COMMANDS [ command . to_sym ] [ :lambda ] . call ( args , output : output , **options . merge ( messages : messages ) )
528+ COMMANDS [ command . to_sym ] [ :lambda ] . call ( args ,
529+ output : output ,
530+ messages : messages ,
531+ repository : repository ,
532+ **options )
522533 end
523534
524535 # Normalize messages
0 commit comments