@@ -58,9 +58,10 @@ def self.cli_commands
5858 out = options [ :output ] || $stdout
5959 out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
6060 options = options . merge ( expandContext : options . delete ( :context ) ) if options . has_key? ( :context )
61+ options [ :base ] ||= options [ :base_uri ]
6162 if options [ :format ] == :jsonld
6263 if files . empty?
63- # If files are empty, either use options[:execute]
64+ # If files are empty, either use options[:evaluate] or STDIN
6465 input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
6566 input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
6667 JSON ::LD ::API . expand ( input , validate : false , **options ) do |expanded |
@@ -93,9 +94,10 @@ def self.cli_commands
9394 raise ArgumentError , "Compacting requires a context" unless options [ :context ]
9495 out = options [ :output ] || $stdout
9596 out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
97+ options [ :base ] ||= options [ :base_uri ]
9698 if options [ :format ] == :jsonld
9799 if files . empty?
98- # If files are empty, either use options[:execute]
100+ # If files are empty, either use options[:evaluate] or STDIN
99101 input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
100102 input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
101103 JSON ::LD ::API . compact ( input , options [ :context ] , **options ) do |compacted |
@@ -126,7 +128,7 @@ def self.cli_commands
126128 control : :url2 ,
127129 use : :required ,
128130 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 ) ) } ,
130132 ]
131133 } ,
132134 flatten : {
@@ -137,9 +139,10 @@ def self.cli_commands
137139 lambda : -> ( files , **options ) do
138140 out = options [ :output ] || $stdout
139141 out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
142+ options [ :base ] ||= options [ :base_uri ]
140143 if options [ :format ] == :jsonld
141144 if files . empty?
142- # If files are empty, either use options[:execute]
145+ # If files are empty, either use options[:evaluate] or STDIN
143146 input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
144147 input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
145148 JSON ::LD ::API . flatten ( input , options [ :context ] , **options ) do |flattened |
@@ -173,9 +176,10 @@ def self.cli_commands
173176 raise ArgumentError , "Framing requires a frame" unless options [ :frame ]
174177 out = options [ :output ] || $stdout
175178 out . set_encoding ( Encoding ::UTF_8 ) if RUBY_PLATFORM == "java"
179+ options [ :base ] ||= options [ :base_uri ]
176180 if options [ :format ] == :jsonld
177181 if files . empty?
178- # If files are empty, either use options[:execute]
182+ # If files are empty, either use options[:evaluate] or STDIN
179183 input = options [ :evaluate ] ? StringIO . new ( options [ :evaluate ] ) : STDIN
180184 input . set_encoding ( options . fetch ( :encoding , Encoding ::UTF_8 ) )
181185 JSON ::LD ::API . frame ( input , options [ :frame ] , **options ) do |framed |
@@ -207,7 +211,7 @@ def self.cli_commands
207211 control : :url2 ,
208212 use : :required ,
209213 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 ) ) }
211215 ]
212216 } ,
213217 }
0 commit comments