@@ -58,9 +58,10 @@ def self.cli_commands
58
58
out = options [ :output ] || $stdout
59
59
out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
60
60
options = options . merge ( expandContext : options . delete ( :context ) ) if options . has_key? ( :context )
61
+ options [ :base ] ||= options [ :base_uri ]
61
62
if options [ :format ] == :jsonld
62
63
if files . empty?
63
- # If files are empty, either use options[:execute]
64
+ # If files are empty, either use options[:evaluate] or STDIN
64
65
input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
65
66
input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
66
67
JSON ::LD ::API . expand ( input , validate : false , **options ) do |expanded |
@@ -93,9 +94,10 @@ def self.cli_commands
93
94
raise ArgumentError , "Compacting requires a context" unless options [ :context ]
94
95
out = options [ :output ] || $stdout
95
96
out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
97
+ options [ :base ] ||= options [ :base_uri ]
96
98
if options [ :format ] == :jsonld
97
99
if files . empty?
98
- # If files are empty, either use options[:execute]
100
+ # If files are empty, either use options[:evaluate] or STDIN
99
101
input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
100
102
input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
101
103
JSON ::LD ::API . compact ( input , options [ :context ] , **options ) do |compacted |
@@ -126,7 +128,7 @@ def self.cli_commands
126
128
control : :url2 ,
127
129
use : :required ,
128
130
on : [ "--context CONTEXT" ] ,
129
- description : "Context to use when compacting." ) { |arg | RDF ::URI ( arg ) } ,
131
+ description : "Context to use when compacting." ) { |arg | RDF ::URI ( arg ) . absolute? ? RDF :: URI ( arg ) : StringIO . new ( File . read ( arg ) ) } ,
130
132
]
131
133
} ,
132
134
flatten : {
@@ -137,9 +139,10 @@ def self.cli_commands
137
139
lambda : -> ( files , **options ) do
138
140
out = options [ :output ] || $stdout
139
141
out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
142
+ options [ :base ] ||= options [ :base_uri ]
140
143
if options [ :format ] == :jsonld
141
144
if files . empty?
142
- # If files are empty, either use options[:execute]
145
+ # If files are empty, either use options[:evaluate] or STDIN
143
146
input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
144
147
input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
145
148
JSON ::LD ::API . flatten ( input , options [ :context ] , **options ) do |flattened |
@@ -173,9 +176,10 @@ def self.cli_commands
173
176
raise ArgumentError , "Framing requires a frame" unless options [ :frame ]
174
177
out = options [ :output ] || $stdout
175
178
out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
179
+ options [ :base ] ||= options [ :base_uri ]
176
180
if options [ :format ] == :jsonld
177
181
if files . empty?
178
- # If files are empty, either use options[:execute]
182
+ # If files are empty, either use options[:evaluate] or STDIN
179
183
input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
180
184
input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
181
185
JSON ::LD ::API . frame ( input , options [ :frame ] , **options ) do |framed |
@@ -207,7 +211,7 @@ def self.cli_commands
207
211
control : :url2 ,
208
212
use : :required ,
209
213
on : [ "--frame FRAME" ] ,
210
- description : "Frame to use when serializing." ) { |arg | RDF ::URI ( arg ) }
214
+ description : "Frame to use when serializing." ) { |arg | RDF ::URI ( arg ) . absolute? ? RDF :: URI ( arg ) : StringIO . new ( File . read ( arg ) ) }
211
215
]
212
216
} ,
213
217
}
0 commit comments