Skip to content

Commit d1da2c2

Browse files
committed
Add CLI to_sxp option to patch command.
1 parent 94d7d78 commit d1da2c2

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

bin/ldpatch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def run(graph, options = {})
2222

2323
patch = LD::Patch.parse(options[:patch], options)
2424

25-
puts ("\nSSE:\n" + patch.to_sse) if options[:debug] || options[:to_sse]
25+
puts ("\nSXP:\n" + patch.to_sse) if options[:debug] || options[:to_sxp]
2626

27-
unless options[:to_sse]
27+
unless options[:to_sxp]
2828
res = patch.execute(graph, options)
2929
puts res.dump(:ttl, base_uri: patch.base_uri, prefixes: patch.prefixes, standard_prefixes: true)
3030
end
@@ -35,7 +35,7 @@ opts = GetoptLong.new(
3535
["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
3636
["--patch", GetoptLong::REQUIRED_ARGUMENT],
3737
["--progress", GetoptLong::NO_ARGUMENT],
38-
["--to-sse", GetoptLong::NO_ARGUMENT],
38+
["--to-sxp", GetoptLong::NO_ARGUMENT],
3939
["--validate", GetoptLong::NO_ARGUMENT],
4040
["--verbose", GetoptLong::NO_ARGUMENT],
4141
["--help", "-?", GetoptLong::NO_ARGUMENT]
@@ -50,7 +50,7 @@ opts.each do |opt, arg|
5050
when '--execute' then options[:patch] = arg
5151
when '--patch' then options[:patch] = RDF::Util::File.open_file(arg).read
5252
when '--progress' then options[:debug] ||= 2
53-
when '--to-sse' then options[:to_sse] = true
53+
when '--to-sxp' then options[:to_sxp] = true
5454
when '--validate' then options[:validate] = true
5555
when '--verbose' then options[:verbose] = true
5656
when "--help"
@@ -61,7 +61,7 @@ opts.each do |opt, arg|
6161
puts " --execute,-e: Use option argument as the patch input"
6262
puts " --patch: Location of patch document"
6363
puts " --progress Display parse tree"
64-
puts " --to-sse: Generate SSE for patch instead of running query"
64+
puts " --to-sxp: Generate S-Expression for patch instead of running query"
6565
puts " --validate: Validate patch document"
6666
puts " --verbose: Display details of processing"
6767
puts " --help,-?: This message"

lib/ld/patch/format.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def self.cli_commands
3232
raise ArgumentError, "Patching requires a URI encoded patch or reference to patch resource" unless opts[:patch]
3333
opts[:logger].info "Patch"
3434
patch = LD::Patch.parse(opts[:patch], base_uri: opts.fetch(:patch_file, "http://rubygems.org/gems/ld-patch"))
35+
opts[:messages][:"S-Expression"] = [patch.to_sse]
3536
RDF::CLI.repository.query(patch)
3637
end,
3738
options: [
@@ -49,6 +50,13 @@ def self.cli_commands
4950
on: ["--patch-file URI"],
5051
description: "Patch file"
5152
) {|v| RDF::URI(v)},
53+
RDF::CLI::Option.new(
54+
symbol: :to_sxp,
55+
datatype: String,
56+
control: :checkbox,
57+
on: ["--to-sxp"],
58+
description: "Instead of patching repository, display parsed patch as an S-Expression"
59+
) {|v| RDF::URI(v)},
5260
]
5361
}
5462
}

0 commit comments

Comments
 (0)