Skip to content

Commit

Permalink
fix to work with new file path
Browse files Browse the repository at this point in the history
  • Loading branch information
masa21kik committed Jun 8, 2014
1 parent f6bddfa commit 477a59d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions bin/json_cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby

require 'json_cli'
JsonCli::CLI.start(ARGV)
1 change: 1 addition & 0 deletions lib/json_cli.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'json_cli/version'
require 'json_cli/cli'
require 'json_cli/command/base'
require 'json_cli/command/join'
require 'json_cli/command/unwind'
Expand Down
14 changes: 5 additions & 9 deletions lib/json_cli/cli.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env ruby
require 'json_cli'
require 'thor'

module JsonCli
Expand All @@ -12,7 +10,7 @@ class CLI < Thor
def left_join(right_file, left_file = '/dev/stdin')
left_io = File.open(left_file, 'r')
right_io = File.open(right_file, 'r')
JsonCli::Command::Join.left_join(left_io, right_io, opts)
JsonCli::Command::Join.new(left_io, right_io, opts).left_join
[left_io, right_io, opts[:out]].each(&:close)
end

Expand All @@ -21,7 +19,7 @@ def left_join(right_file, left_file = '/dev/stdin')
def right_join(right_file, left_file = '/dev/stdin')
left_io = File.open(left_file, 'r')
right_io = File.open(right_file, 'r')
JsonCli::Command::Join.right_join(left_io, right_io, opts)
JsonCli::Command::Join.new(left_io, right_io, opts).right_join
[left_io, right_io, opts[:out]].each(&:close)
end

Expand All @@ -30,15 +28,15 @@ def right_join(right_file, left_file = '/dev/stdin')
def inner_join(right_file, left_file = '/dev/stdin')
left_io = File.open(left_file, 'r')
right_io = File.open(right_file, 'r')
JsonCli::Command::Join.inner_join(left_io, right_io, opts)
JsonCli::Command::Join.new(left_io, right_io, opts).inner_join
[left_io, right_io, opts[:out]].each(&:close)
end

desc 'unwind_array [JSON_FILE]', 'unwind array of json file'
option :unwind_key, required: true, aliases: :k
def unwind_array(json_file = '/dev/stdin')
io = File.open(json_file, 'r')
JsonCli::Command::Unwind.unwind_array(io, opts)
JsonCli::Command::Unwind.new(io, opts).unwind_array
[io, opts[:out]].each(&:close)
end

Expand All @@ -49,7 +47,7 @@ def unwind_array(json_file = '/dev/stdin')
option :value_label
def unwind_hash(json_file = '/dev/stdin')
io = File.open(json_file, 'r')
JsonCli::Command::Unwind.unwind_hash(io, opts)
JsonCli::Command::Unwind.new(io, opts).unwind_hash
[io, opts[:out]].each(&:close)
end

Expand All @@ -64,5 +62,3 @@ def opts
end
end
end

JsonCli::CLI.start(ARGV)

0 comments on commit 477a59d

Please sign in to comment.