dorian-sort-json 0.1.0 → 0.4.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 593c7abd174aae6b4c56ee3793296ddd73a0df8212471a12f646ddd7b22d9b9a
4
- data.tar.gz: 851ad6aac98770aaf060c6be7df99e99d4905bcbf8cc9480c5bb4e887920ef60
3
+ metadata.gz: bf9b0042976b5aae24287008ac779c91e1f7cc07e552b0c88a84057277302923
4
+ data.tar.gz: 9b19afe31fdadbf4577002fb7520e22be5216950633df8ca7c97ec4672bbb220
5
5
  SHA512:
6
- metadata.gz: b0868044f9a658562ce8bc8322bc0abc870557ab111fde02ea54e4e176d1436d651db4e27685ed04b652a3693d8df5c876c5f8e3d47633c729bf7379ebef76e2
7
- data.tar.gz: 84acbecf575d1c0c6100e257b8411ebb895bd6049ccc7d301fb6715522d489b5c3d9d6378a43c478fd7310868d14a0ed10f27899a6a8d2f8abdd467f87a87f8b
6
+ metadata.gz: 49443a56012530f9a6ecaaca2ca7b6774b6282581ab4a76f860ba70f1e614488f213205022d394fbe985fca29e403a63dd1712402d3909c5adfb8e8f5fb48a65
7
+ data.tar.gz: 147f9d9f546088085336faf909e3ad713c7040727d6e34e67b054e9deb7b20dbae30baa6f1c1ed436262ad08a05a14036d528e3c99b941c1e639603be2966fa1
data/bin/sort-json CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require 'dorian/sort-json'
4
+ require "dorian/sort-json"
4
5
  Dorian::SortJson.run
@@ -1,19 +1,33 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
2
4
 
3
5
  module Dorian
4
6
  class SortJson
5
7
  def self.run
6
- if ARGV.size < 1
7
- puts 'USAGE: sort-json FILE [FILE...]'
8
+ if ARGV[0] == "--help" || ARGV[0] == "-h"
9
+ puts "USAGE: sort-json FILES..."
10
+ puts "USAGE: ... | sort-json"
8
11
  exit
9
12
  end
10
13
 
11
- ARGV.each do |filepath|
12
- File.write(
13
- filepath,
14
- JSON.pretty_generate(sort_json(JSON.parse(File.read(filepath)))) +
15
- "\n"
16
- )
14
+ inputs = ARGV
15
+
16
+ if inputs.empty?
17
+ inputs = $stdin.each_line.to_a
18
+
19
+ inputs =
20
+ if File.exist?(inputs.first.strip)
21
+ inputs.map(&:strip)
22
+ else
23
+ [inputs.join]
24
+ end
25
+ end
26
+
27
+ inputs.each do |input|
28
+ content = File.exist?(input) ? File.read(input) : input
29
+ json = "#{JSON.pretty_generate(sort_json(JSON.parse(content)))}\n"
30
+ File.exist?(input) ? File.write(input, json) : puts(json)
17
31
  end
18
32
  end
19
33
 
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.1.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-10 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Sorts keys of hashes of JSON files
@@ -22,10 +22,11 @@ extra_rdoc_files: []
22
22
  files:
23
23
  - bin/sort-json
24
24
  - lib/dorian/sort-json.rb
25
- homepage: https://github.com/dorianmariefr/sort-json
25
+ homepage: https://github.com/dorianmariecom/sort-json
26
26
  licenses:
27
27
  - MIT
28
- metadata: {}
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
29
30
  post_install_message:
30
31
  rdoc_options: []
31
32
  require_paths:
@@ -41,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
42
  - !ruby/object:Gem::Version
42
43
  version: '0'
43
44
  requirements: []
44
- rubygems_version: 3.2.22
45
+ rubygems_version: 3.5.3
45
46
  signing_key:
46
47
  specification_version: 4
47
48
  summary: Sorts keys of hashes of JSON files