dorian-sort-json 0.1.0 → 0.4.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/lib/dorian/sort-json.rb +20 -9
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 593c7abd174aae6b4c56ee3793296ddd73a0df8212471a12f646ddd7b22d9b9a
4
- data.tar.gz: 851ad6aac98770aaf060c6be7df99e99d4905bcbf8cc9480c5bb4e887920ef60
3
+ metadata.gz: 044bd64a6db1e47c642b1495bd3f03e0217555a37a9fc1a186a8e5001b252f4a
4
+ data.tar.gz: ada1eadd785f91c4469f034c15b3143bb44677aa36dce794501ce1d2427f1678
5
5
  SHA512:
6
- metadata.gz: b0868044f9a658562ce8bc8322bc0abc870557ab111fde02ea54e4e176d1436d651db4e27685ed04b652a3693d8df5c876c5f8e3d47633c729bf7379ebef76e2
7
- data.tar.gz: 84acbecf575d1c0c6100e257b8411ebb895bd6049ccc7d301fb6715522d489b5c3d9d6378a43c478fd7310868d14a0ed10f27899a6a8d2f8abdd467f87a87f8b
6
+ metadata.gz: 9efa6990cc8b57177e8d40a965461131e101095612a3dfe41ff77363d04e432e4c587f96372850534841d0ee4349518fdac6118072692eab9a07df94007abe50
7
+ data.tar.gz: 6ea7b8307b8997cd0251b82111979b2b8b47909d884e4ac2d68763e992a9e9564a239d61c3392fe1f79985491df1b550158a109ce70d73ab84f2449f5fbd447b
@@ -1,19 +1,30 @@
1
- require 'json'
1
+ require "json"
2
2
 
3
3
  module Dorian
4
4
  class SortJson
5
5
  def self.run
6
- if ARGV.size < 1
7
- puts 'USAGE: sort-json FILE [FILE...]'
6
+ if ARGV[0] == "--help" || ARGV[0] == "-h"
7
+ puts "USAGE: sort-json FILES..."
8
+ puts "USAGE: ... | sort-json"
8
9
  exit
9
10
  end
10
11
 
11
- ARGV.each do |filepath|
12
- File.write(
13
- filepath,
14
- JSON.pretty_generate(sort_json(JSON.parse(File.read(filepath)))) +
15
- "\n"
16
- )
12
+ inputs = ARGV
13
+
14
+ if inputs.size.zero?
15
+ inputs = STDIN.each_line.to_a
16
+
17
+ if File.exist?(inputs.first.strip)
18
+ inputs = inputs.map(&:strip)
19
+ else
20
+ inputs = [inputs.join]
21
+ end
22
+ end
23
+
24
+ inputs.each do |input|
25
+ content = File.exist?(input) ? File.read(input) : input
26
+ json = JSON.pretty_generate(sort_json(JSON.parse(content))) + "\n"
27
+ File.exist?(input) ? File.write(input, json) : puts(json)
17
28
  end
18
29
  end
19
30
 
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.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: 2021-10-10 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Sorts keys of hashes of JSON files
@@ -25,7 +25,8 @@ files:
25
25
  homepage: https://github.com/dorianmariefr/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: