dorian-sort-json 0.5.3 → 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 +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dbe17f465be829e3eab4c1c4880d537657628287082b5a1d79bbabf8e21aa18
4
- data.tar.gz: 325ec5b82ede8f063819bc0237d426f9f7c4f2ff15e35855f32e88f765677b2f
3
+ metadata.gz: 38d2e31702100c63cfb56fd8074e16a70035391d591cfc45865b7c2f120ec0a2
4
+ data.tar.gz: e17b9bb93b7906a212f0834cb2262242ba10d4bca61fd3c052e40737677748c3
5
5
  SHA512:
6
- metadata.gz: ccba6b7a5756567dfbb31511c40dbd3fab876ee65cea4b18525b03b8c51ecdd85eedcbc903aebc9aa518b0e6eaeb38056a25458d3d246781e5f8bd1f7c08817b
7
- data.tar.gz: 36d5bb4569059c1bca988784f7d062cc692903b10816f9f82c5e1288aa9f8bb1463151a9ec44b9e1ed9d8fc7e511d5e0061bc0021267440f616423733896c3d8
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-sort-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
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-22 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dorian-arguments