dorian-sort-yaml 0.1.0 → 0.2.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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dorian/sort-yaml.rb +20 -8
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bad7f8409471b619ce00f1b0603e38e896f93313df355fcb9e72e4ce49ecc0c
4
- data.tar.gz: f2bac6f4510d1e8c1be8f006323ddbac80f519a3c9e2ec085041fc0ad3b9e3c0
3
+ metadata.gz: c0eb22995aee743070ed7cf87ffb82a950b0b43d103ef58b868ba7b51d51fcea
4
+ data.tar.gz: 6f937776f666c0c816469e01d05b8a60f1e28fc9e2cf7301855fd4cfcbe5c707
5
5
  SHA512:
6
- metadata.gz: cea5b954a402a7d658978d057169fe6f2f362bae969a730b951afb028eb9a864756406a5bc637556ca730a0b9a67300df9077132694555ca8cf4953807c9bf29
7
- data.tar.gz: db6913ff0487f54aad2b60897174024d3e9ef6da472bf5c245fea923f066d30299ed3af1e9f00042c746c1e3a3c0f2046d1610c6847acbb4259a4159724855dd
6
+ metadata.gz: 00c7e0d660544b423a3ba5447965346065b76c74984920f2a9f6f89861e07556c5f5e8d0d0771faf346d508a7d36784c5059e7ab1fe9c93e897f4bc44c2fd512
7
+ data.tar.gz: 5e5110eaa5934677acdfab2f0ee7b0a48aef2c19e46f0bb8dca66b9715669e5f224fed39f1ba0802deabce247aec36f3b76dc4e8b58194211da21511593144c8
@@ -1,18 +1,30 @@
1
- require 'yaml'
1
+ require "yaml"
2
2
 
3
3
  module Dorian
4
4
  class SortYaml
5
5
  def self.run
6
- if ARGV.size < 1
7
- puts 'USAGE: sort-yaml FILE [FILE...]'
6
+ if ARGV[0] == "--help" || ARGV[0] == "-h"
7
+ puts "USAGE: sort-yaml FILES..."
8
+ puts "USAGE: ... | sort-yaml"
8
9
  exit
9
10
  end
10
11
 
11
- ARGV.each do |filepath|
12
- File.write(
13
- filepath,
14
- sort_yaml(YAML.safe_load(File.read(filepath))).to_yaml
15
- )
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
+ yaml = sort_yaml(YAML.safe_load(File.read(filepath))).to_yaml
27
+ File.exist?(input) ? File.write(input, yaml) : puts(yaml)
16
28
  end
17
29
  end
18
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-sort-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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 YAML files
@@ -25,7 +25,8 @@ files:
25
25
  homepage: https://github.com/dorianmariefr/sort-yaml
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: