dorian-sort-json 0.5.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sort-json +27 -14
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bc0a86ad96f4811c115f18ea229722a01b40918e703842e4927e3d89dce96f3
4
- data.tar.gz: 013364f53bf664e0370896c063f1481bde696794ecadde7d945694756a248004
3
+ metadata.gz: 38d2e31702100c63cfb56fd8074e16a70035391d591cfc45865b7c2f120ec0a2
4
+ data.tar.gz: e17b9bb93b7906a212f0834cb2262242ba10d4bca61fd3c052e40737677748c3
5
5
  SHA512:
6
- metadata.gz: 401d46e3a1183cba65f5b94519613077e0945a35134aa1d83d38fe459cbba3aecd123804caad2fbcaf4d9046fef91a34402a556302b007f179b6c233fe091ccd
7
- data.tar.gz: c8c01fff3ec498a41135a74f6c6da356eec86beb5395445d17f4d115e190c0e8aa6d1ab663b67e3de8dc88d2d4b8d18167b95e8e60e748753bb764f33c9a0cb5
6
+ metadata.gz: d6fc168c02e1961efd764fd5788839057650524ed196596904000e9c78bfdd3e62686e98136b5900f60f427e4650b867b5c19d615d0d1a20b88f7effd1d80684
7
+ data.tar.gz: '0418f36e2619992b282e485c741fba68df4f0bfec63fb8f580b5fa9d6b20737d0638dfbd5279b69b09b5534b339b9d9a7ba53b2e9650392cb0d31cc8e85e4be3'
data/bin/sort-json CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "dorian/arguments"
4
5
  require "json"
5
6
 
6
7
  def sort_json(data)
@@ -16,23 +17,35 @@ def sort_json(data)
16
17
  end
17
18
  end
18
19
 
19
- if ARGV[0] == "--help" || ARGV[0] == "-h"
20
- puts "USAGE: sort-json FILES..."
21
- puts "USAGE: ... | sort-json"
22
- exit
23
- end
24
-
25
- inputs = ARGV
20
+ parsed =
21
+ Dorian::Arguments.parse(
22
+ pretty: {
23
+ alias: :p,
24
+ default: true
25
+ },
26
+ version: {
27
+ alias: :v
28
+ },
29
+ help: {
30
+ alias: :h
31
+ }
32
+ )
26
33
 
27
- if inputs.empty?
28
- inputs = $stdin.each_line.to_a
34
+ abort parsed.help if parsed.options.help
29
35
 
30
- inputs =
31
- (File.exist?(inputs.first.strip) ? inputs.map(&:strip) : [inputs.join])
36
+ if parsed.options.version
37
+ abort File.read(File.expand_path("../../VERSION", __FILE__))
32
38
  end
33
39
 
40
+ inputs = parsed.arguments + parsed.files.map { |file| File.read(file) }
41
+ inputs = [$stdin.each_line.to_a.map(&:strip).join("\n")] if inputs.empty?
42
+
34
43
  inputs.each do |input|
35
- content = File.exist?(input) ? File.read(input) : input
36
- json = "#{JSON.pretty_generate(sort_json(JSON.parse(content)))}\n"
37
- File.exist?(input) ? File.write(input, json) : puts(json)
44
+ output = sort_json(JSON.parse(input))
45
+
46
+ if parsed.options.pretty
47
+ puts JSON.pretty_generate(output)
48
+ else
49
+ puts output.to_json
50
+ end
38
51
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-sort-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dorian-arguments
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: sorts json
14
28
  email: dorian@dorianmarie.com
15
29
  executables: