jpp 0.1 → 1.0.0

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/LICENSE.md +22 -0
  2. data/README.md +8 -2
  3. data/lib/jpp.rb +14 -6
  4. metadata +3 -2
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Benton Porter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -25,8 +25,14 @@ More usage:
25
25
  Install
26
26
  -------
27
27
 
28
- You currently have to clone the repo and build/install the gem.
28
+ gem install jpp
29
+
30
+
31
+ Contribute
32
+ ----------
33
+
34
+ To build and run locally:
29
35
 
30
36
  git clone git@github.com:bentonporter/jpp.git
31
37
  cd jpp
32
- gem build jpp.gemspec && gem install jpp-0.1.gem
38
+ gem build jpp.gemspec && gem install jpp-1.0.0.gem
data/lib/jpp.rb CHANGED
@@ -1,18 +1,26 @@
1
1
  require 'json'
2
2
  require 'optparse'
3
+ require 'ostruct'
3
4
  require 'hash'
4
5
 
5
6
  class Jpp
6
- VERSION = '0.1'
7
+ VERSION = '1.0.0'
7
8
 
8
9
  def main()
9
- options = {}
10
+ # Set default values
11
+ options = OpenStruct.new
12
+ options.indent = 2
13
+ options.sort = false
10
14
 
11
15
  parser = OptionParser.new do |opts|
12
16
  opts.banner = 'Usage: jpp [options] file'
13
17
 
18
+ opts.on('-i', '--indent N', Integer, "Number of spaces to indent (default: #{options.indent}) ") do |i|
19
+ options.indent = i
20
+ end
21
+
14
22
  opts.on('-s', '--sort', 'Sort json alphabetically by key') do |s|
15
- options[:sort] = s
23
+ options.sort = s
16
24
  end
17
25
 
18
26
  opts.on('-v', '--version', 'Show version') do |v|
@@ -22,15 +30,15 @@ class Jpp
22
30
  end
23
31
 
24
32
  begin parser.parse!
25
- rescue OptionParser::InvalidOption => message
33
+ rescue OptionParser::ParseError => message
26
34
  puts message
27
35
  puts parser
28
36
  exit 1
29
37
  end
30
38
 
31
39
  input = JSON.load(ARGF.read)
32
- input = input.sort_by_key() if options[:sort]
33
- output = JSON.pretty_generate(input)
40
+ input = input.sort_by_key() if options.sort
41
+ output = JSON.pretty_generate(input, :indent => ' ' * options.indent)
34
42
  puts output
35
43
  end
36
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpp
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,6 +37,7 @@ files:
37
37
  - bin/jpp
38
38
  - ext/hash.rb
39
39
  - lib/jpp.rb
40
+ - LICENSE.md
40
41
  - README.md
41
42
  homepage: https://github.com/bentonporter/jpp
42
43
  licenses: []
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  version: '0'
60
61
  requirements: []
61
62
  rubyforge_project:
62
- rubygems_version: 1.8.23
63
+ rubygems_version: 1.8.25
63
64
  signing_key:
64
65
  specification_version: 3
65
66
  summary: Command-line JSON pretty-printer