apjson 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/apjson.gemspec +1 -1
  3. data/bin/apjson +32 -1
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/apjson.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "apjson"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["haracane"]
data/bin/apjson CHANGED
@@ -19,6 +19,23 @@ while arg = ARGV.shift
19
19
  pp_flag = true
20
20
  when "--puts"
21
21
  puts_flag = true
22
+ when "--puts"
23
+ puts_flag = true
24
+ when "-i"
25
+ input_file = ARGV.shift
26
+ when "--input"
27
+ input_file = ARGV.shift
28
+ when "--help"
29
+ puts <<-EOF
30
+ usage: apjson [--p] [--pp] [--ap] [--puts]
31
+ [--input <path>] [--help] [<args>]
32
+ --p print by p method
33
+ --pp print by pretty print
34
+ --ap print by awesome print
35
+ --puts print by puts method
36
+ -i, --input FILE read from FILE
37
+ EOF
38
+ exit 0
22
39
  else
23
40
  args.push arg
24
41
  end
@@ -26,7 +43,21 @@ end
26
43
 
27
44
  ARGV.push *args
28
45
 
29
- input = STDIN.read
46
+ if input_file
47
+ unless File.exists?(input_file)
48
+ STDERR.puts "ERROR: #{input_file} does not exist."
49
+ exit 1
50
+ end
51
+ f = open(input_file)
52
+ if f.nil?
53
+ STDERR.puts "ERROR: could not open #{input_file}"
54
+ exit 1
55
+ end
56
+ input = f.read
57
+ f.close
58
+ else
59
+ input = STDIN.read
60
+ end
30
61
 
31
62
  result = JSON.parse("#{input.gsub(/\r?\n/, "")}")
32
63
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apjson
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - haracane