|
25 | 25 | rdf/xsd |
26 | 26 | shacl |
27 | 27 | shex |
| 28 | + yaml_ld |
28 | 29 | ).each do |ser| |
29 | 30 | begin |
30 | 31 | require ser |
@@ -177,7 +178,10 @@ def to_hash |
177 | 178 | # * `parse` Boolean value to determine if input files should automatically be parsed into `repository`. |
178 | 179 | # * `help` used for the CLI help output. |
179 | 180 | # * `lambda` code run to execute command. |
180 | | - # * `filter` Option values that must match for command to be used |
| 181 | + # * `filter` value is a Hash whose keys are matched against selected command options. All specified `key/value` pairs are compared against the equivalent key in the current invocation. |
| 182 | + # If an Array, option value (as a string) must match any value of the array (as a string) |
| 183 | + # If a Proc, it is passed the option value and must return `true`. |
| 184 | + # Otherwise, the option value (as a string) must equal the `value` (as a string). |
181 | 185 | # * `control` Used to indicate how (if) command is displayed |
182 | 186 | # * `repository` Use this repository, if set |
183 | 187 | # * `options` an optional array of `RDF::CLI::Option` describing command-specific options. |
@@ -505,9 +509,22 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options |
505 | 509 | # Make sure any selected command isn't filtered out |
506 | 510 | cmds.each do |c| |
507 | 511 | COMMANDS[c.to_sym].fetch(:filter, {}).each do |opt, val| |
508 | | - if options[opt].to_s != val.to_s |
509 | | - usage(option_parser, banner: "Command #{c.inspect} requires #{opt}: #{val}, not #{options.fetch(opt, 'null')}") |
510 | | - raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}" |
| 512 | + case val |
| 513 | + when Array |
| 514 | + unless val.map(&:to_s).include?(options[opt].to_s) |
| 515 | + usage(option_parser, banner: "Command #{c.inspect} requires #{opt} in #{val.map(&:to_s).inspect}, not #{options.fetch(opt, 'null')}") |
| 516 | + raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}" |
| 517 | + end |
| 518 | + when Proc |
| 519 | + unless val.call(options[opt]) |
| 520 | + usage(option_parser, banner: "Command #{c.inspect} #{opt} inconsistent with #{options.fetch(opt, 'null')}") |
| 521 | + raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}" |
| 522 | + end |
| 523 | + else |
| 524 | + unless val.to_s == options[opt].to_s |
| 525 | + usage(option_parser, banner: "Command #{c.inspect} requires compatible value for #{opt}, not #{options.fetch(opt, 'null')}") |
| 526 | + raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}" |
| 527 | + end |
511 | 528 | end |
512 | 529 | end |
513 | 530 |
|
@@ -594,7 +611,14 @@ def self.commands(format: nil, **options) |
594 | 611 | # Subset commands based on filter options |
595 | 612 | cmds = COMMANDS.reject do |k, c| |
596 | 613 | c.fetch(:filter, {}).any? do |opt, val| |
597 | | - options.merge(format: format)[opt].to_s != val.to_s |
| 614 | + case val |
| 615 | + when Array |
| 616 | + !val.map(&:to_s).include?(options[opt].to_s) |
| 617 | + when Proc |
| 618 | + !val.call(options[opt]) |
| 619 | + else |
| 620 | + val.to_s != options[opt].to_s |
| 621 | + end |
598 | 622 | end |
599 | 623 | end |
600 | 624 |
|
|
0 commit comments