Skip to content

Commit ab60e9e

Browse files
committed
Update patch CLI to allow patch_file to come from StringIO. Add other elements to enable HTML UI.
1 parent 8460850 commit ab60e9e

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/ld/patch/format.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,33 @@ class Format < RDF::Format
2020
def self.cli_commands
2121
{
2222
patch: {
23-
description: "Patch the current graph using a URI Encoded patch file, or a referenced path file/URI",
23+
description: "Patch the current graph using a patch file",
2424
help: "patch [--patch 'patch'] [--patch-file file]",
2525
parse: true,
2626
lambda: -> (argv, opts) do
27-
opts[:patch] ||= RDF::Util::File.open_file(opts[:patch_file]) {|f| f.read}
27+
opts[:patch] ||= case opts[:patch_file]
28+
when IO, StringIO then opts[:patch_file]
29+
else RDF::Util::File.open_file(opts[:patch_file]) {|f| f.read}
30+
end
2831
raise ArgumentError, "Patching requires a URI encoded patch or reference to patch resource" unless opts[:patch]
29-
$stdout.puts "Patch"
32+
opts[:logger].info "Patch"
3033
patch = LD::Patch.parse(opts[:patch], base_uri: opts.fetch(:patch_file, "http://rubygems.org/gems/ld-patch"))
3134
RDF::CLI.repository.query(patch)
3235
end,
3336
options: [
3437
RDF::CLI::Option.new(
3538
symbol: :patch,
3639
datatype: String,
40+
control: :none,
3741
on: ["--patch STRING"],
3842
description: "Patch in URI encoded format"
3943
) {|v| URI.decode(v)},
4044
RDF::CLI::Option.new(
4145
symbol: :patch_file,
4246
datatype: String,
47+
control: :url2,
4348
on: ["--patch-file URI"],
44-
description: "URI of patch file"
49+
description: "Patch file"
4550
) {|v| RDF::URI(v)},
4651
]
4752
}

spec/format_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
specify {expect(described_class.to_sym).to eq :ldpatch}
2727
end
2828

29-
describe ".cli_commands", skip: ("TextMate OptionParser issues" if ENV['TM_SELECTED_FILE']) do
29+
describe ".cli_commands" do
3030
require 'rdf/cli'
3131
let(:nt) {File.expand_path("../test-files/1triple.nt", __FILE__)}
3232
let(:patch) {File.expand_path("../test-files/add-1triple.ldpatch", __FILE__)}
@@ -36,6 +36,9 @@
3636
it "patches from file" do
3737
expect {RDF::CLI.exec(["patch", "serialize", nt], patch_file: patch)}.to write.to(:output)
3838
end
39+
it "patches from StringIO" do
40+
expect {RDF::CLI.exec(["patch", "serialize", nt], patch_file: StringIO.new(File.read(patch)))}.to write.to(:output)
41+
end
3942
it "patches from argument" do
4043
expect {RDF::CLI.exec(["patch", "serialize", nt], patch: patch_enc)}.to write.to(:output)
4144
end

0 commit comments

Comments
 (0)