lib/ld/patch/format.rb in ld-patch-0.3.1 vs lib/ld/patch/format.rb in ld-patch-0.3.2
- old
+ new
@@ -18,32 +18,46 @@
# Hash of CLI commands appropriate for this format
# @return [Hash{Symbol => Lambda(Array, Hash)}]
def self.cli_commands
{
patch: {
- description: "Patch the current graph using a URI Encoded patch file, or a referenced path file/URI",
- help: "patch [--patch 'patch'] [--patch-file file]",
+ description: "Patch the current graph using a patch file",
+ help: "patch [--patch-input 'patch'] [--patch-file file]",
+ control: :button,
parse: true,
lambda: -> (argv, opts) do
- opts[:patch] ||= RDF::Util::File.open_file(opts[:patch_file]) {|f| f.read}
- raise ArgumentError, "Patching requires a URI encoded patch or reference to patch resource" unless opts[:patch]
- $stdout.puts "Patch"
- patch = LD::Patch.parse(opts[:patch], base_uri: opts.fetch(:patch_file, "http://rubygems.org/gems/ld-patch"))
+ opts[:patch_input] ||= case opts[:patch_file]
+ when IO, StringIO then opts[:patch_file]
+ else RDF::Util::File.open_file(opts[:patch_file]) {|f| f.read}
+ end
+ raise ArgumentError, "Patching requires a patch or reference to patch resource" unless opts[:patch_input]
+ opts[:logger].info "Patch"
+ patch = LD::Patch.parse(opts[:patch_input], base_uri: opts.fetch(:patch_file, "http://rubygems.org/gems/ld-patch"))
+ opts[:messages][:"S-Expression"] = [patch.to_sse] if opts[:to_sxp]
RDF::CLI.repository.query(patch)
end,
options: [
RDF::CLI::Option.new(
- symbol: :patch,
+ symbol: :patch_input,
datatype: String,
- on: ["--patch STRING"],
+ control: :none,
+ on: ["--patch-input STRING"],
description: "Patch in URI encoded format"
) {|v| URI.decode(v)},
RDF::CLI::Option.new(
symbol: :patch_file,
datatype: String,
+ control: :url2,
on: ["--patch-file URI"],
- description: "URI of patch file"
+ description: "Patch file"
) {|v| RDF::URI(v)},
+ RDF::CLI::Option.new(
+ symbol: :to_sxp,
+ datatype: String,
+ control: :checkbox,
+ on: ["--to-sxp"],
+ description: "Instead of patching repository, display parsed patch as an S-Expression"
+ ),
]
}
}
end