From 5b6920ff69aa23398b211cb03f732a083d8f974e Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 1 Jan 2022 11:55:24 -0500 Subject: [PATCH] Handle optional space in `-L` option (#104) --- README.md | 2 +- shard.yml | 2 +- snap/snapcraft.yaml | 2 +- spec/assets/test.jq | 1 + spec/oq_spec.cr | 12 +++++++++--- spec/spec_helper.cr | 4 ++-- src/oq.cr | 6 +++--- 7 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 spec/assets/test.jq diff --git a/README.md b/README.md index 966c932..3367a7d 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ The built binary will be available as `./bin/oq`. This can be relocated elsewhe ```dockerfile # Set an arg to store the oq version that should be installed. -ARG OQ_VERSION=1.3.1 +ARG OQ_VERSION=1.3.2 # Grab the binary from the latest Github release and make it executable; placing it within /usr/local/bin. Can also put it elsewhere if you so desire. RUN wget https://github.com/Blacksmoke16/oq/releases/download/v${OQ_VERSION}/oq-v${OQ_VERSION}-linux-x86_64 -O /usr/local/bin/oq && chmod +x /usr/local/bin/oq diff --git a/shard.yml b/shard.yml index 0425a5a..913fe68 100644 --- a/shard.yml +++ b/shard.yml @@ -3,7 +3,7 @@ name: oq description: | A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data. -version: 1.3.1 +version: 1.3.2 authors: - George Dietrich diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index aecec93..659cffc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: oq -version: '1.3.1' +version: '1.3.2' summary: A performant, and portable jq wrapper to support formats other than JSON description: | A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data. diff --git a/spec/assets/test.jq b/spec/assets/test.jq new file mode 100644 index 0000000..c4badd3 --- /dev/null +++ b/spec/assets/test.jq @@ -0,0 +1 @@ +def increment: . + 1; diff --git a/spec/oq_spec.cr b/spec/oq_spec.cr index de35b3e..9e4b4a3 100644 --- a/spec/oq_spec.cr +++ b/spec/oq_spec.cr @@ -185,9 +185,15 @@ describe OQ do end describe "with the -L option" do - it "should be passed correctly" do - run_binary(input: SIMPLE_JSON_OBJECT, args: ["-L", "'/home/'", "."]) do |output| - output.should eq %({\n "name": "Jim"\n}\n) + it "should be passed correctly without a space" do + run_binary(args: ["-n", "-L#{__DIR__}/assets", %(import "test" as test; 9 | test::increment)]) do |output| + output.should eq %(10\n) + end + end + + it "should be passed correctly with a space" do + run_binary(args: ["-n", "-L", "#{__DIR__}/assets", %(import "test" as test; 9 | test::increment)]) do |output| + output.should eq %(10\n) end end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 1665771..8dad2df 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -17,9 +17,9 @@ def run_binary(input : String | Process::Redirect | Nil = nil, name : String = " status = Process.run(name, args, output: buffer_io, input: input_io, error: error_io) if success - status.success?.should be_true, file: file, line: line + status.success?.should be_true, file: file, line: line, failure_message: error_io.to_s else - status.success?.should_not be_true, file: file, line: line + status.success?.should_not be_true, file: file, line: line, failure_message: error_io.to_s end yield buffer_io.to_s, status, error_io.to_s diff --git a/src/oq.cr b/src/oq.cr index 2f05c41..1cf81a9 100644 --- a/src/oq.cr +++ b/src/oq.cr @@ -6,7 +6,7 @@ require "./converters/*" # A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data. module OQ - VERSION = "1.3.1" + VERSION = "1.3.2" # The support formats that can be converted to/from. enum Format @@ -145,10 +145,10 @@ module OQ # Register an at_exit handler to cleanup temp files. at_exit { @tmp_files.each &.delete } - # Parse out --rawfile, --argfile, --slurpfile, and -f/--from-file before processing additional args + # Parse out --rawfile, --argfile, --slurpfile,-f/--from-file, and -L before processing additional args # since these options use a file that should not be used as input. self.consume_file_args input_args, "--rawfile", "--argfile", "--slurpfile" - self.consume_file_args input_args, "-f", "--from-file", count: 1 + self.consume_file_args input_args, "-f", "--from-file", "-L", count: 1 # Also parse out --arg, and --argjson as they may include identifiers that also exist as a directory/file # which would result in incorrect arg extraction.