Skip to content

Commit 767c243

Browse files
committed
CLI improvements:
* add `processing_mode` for reader and writer * add `expandContext` for reader * move `compactArrays` to writer * move `frame` from writer to `frame` command. * add filter for expand, compact, flatten and so that they are only applicable when output-format is jsonld. * remove `context` option for expand command.
1 parent 42b1753 commit 767c243

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

lib/json/ld/format.rb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def self.cli_commands
5353
description: "Expand JSON-LD or parsed RDF",
5454
parse: false,
5555
help: "expand [--context <context-file>] files ...",
56+
filter: {output_format: :jsonld}, # Only shows output format set
5657
lambda: ->(files, options) do
5758
out = options[:output] || $stdout
5859
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
@@ -80,11 +81,15 @@ def self.cli_commands
8081
end
8182
end
8283
end
83-
end
84+
end,
85+
options: [
86+
RDF::CLI::Option.new(symbol: :context, on: [])
87+
]
8488
},
8589
compact: {
8690
description: "Compact JSON-LD or parsed RDF",
8791
parse: false,
92+
filter: {output_format: :jsonld}, # Only shows output format set
8893
help: "compact --context <context-file> files ...",
8994
lambda: ->(files, options) do
9095
raise ArgumentError, "Compacting requires a context" unless options[:context]
@@ -115,12 +120,22 @@ def self.cli_commands
115120
end
116121
end
117122
end
118-
end
123+
end,
124+
options: [
125+
RDF::CLI::Option.new(
126+
symbol: :context,
127+
datatype: RDF::URI,
128+
control: :url2,
129+
required: true,
130+
on: ["--context CONTEXT"],
131+
description: "Context to use when compacting.") {|arg| RDF::URI(arg)},
132+
]
119133
},
120134
flatten: {
121135
description: "Flatten JSON-LD or parsed RDF",
122136
parse: false,
123137
help: "flatten [--context <context-file>] files ...",
138+
filter: {output_format: :jsonld}, # Only shows output format set
124139
lambda: ->(files, options) do
125140
out = options[:output] || $stdout
126141
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
@@ -155,6 +170,7 @@ def self.cli_commands
155170
description: "Frame JSON-LD or parsed RDF",
156171
parse: false,
157172
help: "frame --frame <frame-file> files ...",
173+
filter: {output_format: :jsonld}, # Only shows output format set
158174
lambda: ->(files, options) do
159175
raise ArgumentError, "Framing requires a frame" unless options[:frame]
160176
out = options[:output] || $stdout
@@ -184,7 +200,16 @@ def self.cli_commands
184200
end
185201
end
186202
end
187-
end
203+
end,
204+
options: [
205+
RDF::CLI::Option.new(
206+
symbol: :frame,
207+
datatype: RDF::URI,
208+
control: :url2,
209+
required: true,
210+
on: ["--frame FRAME", :REQUIRED],
211+
description: "Frame to use when serializing.") {|arg| RDF::URI(arg)}
212+
]
188213
},
189214
}
190215
end

lib/json/ld/reader.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ class Reader < RDF::Reader
1515
def self.options
1616
super + [
1717
RDF::CLI::Option.new(
18-
symbol: :compactArrays,
19-
datatype: TrueClass,
20-
on: ["--compact-arrays"],
21-
description: "Replaces arrays with just one element with that element during compaction.") {true},
18+
symbol: :expandContext,
19+
control: :url2,
20+
datatype: RDF::URI,
21+
on: ["--expand-context CONTEXT"],
22+
description: "Context to use when expanding.") {|arg| RDF::URI(arg)},
23+
RDF::CLI::Option.new(
24+
symbol: :processing_mode,
25+
datatype: %w(json-ld-1.0 json-ld-1.1),
26+
control: :radio,
27+
on: ["--processingMode MODE", %w(json-ld-1.0 json-ld-1.1)],
28+
description: "Set Processing Mode (json-ld-1.0 or json-ld-1.1)"),
2229
]
2330
end
2431

lib/json/ld/writer.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,37 @@ def self.options
7575
RDF::CLI::Option.new(
7676
symbol: :compactArrays,
7777
datatype: TrueClass,
78+
control: :checkbox,
7879
on: ["--compact-arrays"],
7980
description: "Replaces arrays with just one element with that element during compaction.") {true},
8081
RDF::CLI::Option.new(
8182
symbol: :compactToRelative,
8283
datatype: TrueClass,
84+
control: :checkbox,
8385
on: ["--compact-to-relative"],
8486
description: "Creates document relative IRIs when compacting, if `true`, otherwise leaves expanded. Default is `true` use --no-compact-to-relative to disable.") {true},
8587
RDF::CLI::Option.new(
8688
symbol: :context,
8789
datatype: RDF::URI,
90+
control: :url2,
8891
on: ["--context CONTEXT"],
89-
description: "Context to use when serializing. Constructed context for native serialization.") {|arg| RDF::URI(arg)},
92+
description: "Context to use when compacting.") {|arg| RDF::URI(arg)},
9093
RDF::CLI::Option.new(
91-
symbol: :frame,
92-
datatype: RDF::URI,
93-
on: ["--frame FRAME"],
94-
description: "Frame to use when serializing.") {|arg| RDF::URI(arg)},
94+
symbol: :processing_mode,
95+
datatype: %w(json-ld-1.0 json-ld-1.1),
96+
control: :radio,
97+
on: ["--processingMode MODE", %w(json-ld-1.0 json-ld-1.1)],
98+
description: "Set Processing Mode (json-ld-1.0 or json-ld-1.1)"),
9599
RDF::CLI::Option.new(
96100
symbol: :stream,
97101
datatype: TrueClass,
102+
control: :checkbox,
98103
on: ["--stream"],
99104
description: "Do not attempt to optimize graph presentation, suitable for streaming large graphs.") {true},
100105
RDF::CLI::Option.new(
101106
symbol: :useRdfType,
102107
datatype: TrueClass,
108+
control: :checkbox,
103109
on: ["--use-rdf-type"],
104110
description: "Treat `rdf:type` like a normal property instead of using `@type`.") {true},
105111
]

0 commit comments

Comments
 (0)