dorian-sort-yaml 0.4.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-yaml +9 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d501bc7eb807f62c20d8bca1bf810a597835881383a8b34cd1495ffa904d2d6
4
- data.tar.gz: 49ba17b0700c3dff246e972a477c49f4e98ff70a1b1b6043065f7c080a9437c3
3
+ metadata.gz: 1ff09d214a4ef91af00cbe29f0060e184929d0445807689747cda209d0dc2b0c
4
+ data.tar.gz: 9c7e55f68a02bddf194eb7d23b4a095f2c0e636965063f0f5b22f32cc683ccbb
5
5
  SHA512:
6
- metadata.gz: '034208e4ab6e7d5ef8ec1ba1cdfbb59c65127fc6e57aa966c87ff2318db0b395fee52bf67f187ddd24aa45bbbc6eb927617bd9a6f75f1f4d590b3b50b0f01299'
7
- data.tar.gz: f29540b3d52b9cbc6065ff1b38fd39083a27ab0f2eec6ded316a5c95b42ba3fda9c7d3888923b577e1f8eefade6062c6e8031d7412b613df4fb9144d2d3781c3
6
+ metadata.gz: afc71443f61d6b15e4ef260c03676c6c91a0dbee8aef9e152ef1d84ba25f0f63c11ef78c80be4d4f2da2444154d6d596c8142413ed0a079359091c0afd8ed898
7
+ data.tar.gz: 50ebae0ce7d628d5b0fa86aa9bf7d885eabef86b7a8c9bec054f0af9110c399579a24d007231af6c117ead47afa72a5eba4ff6669fa4a31ea3c1995f263f9c49
data/bin/sort-yaml 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 "yaml"
5
6
 
6
7
  def sort_yaml(data)
@@ -16,23 +17,15 @@ def sort_yaml(data)
16
17
  end
17
18
  end
18
19
 
19
- if ARGV[0] == "--help" || ARGV[0] == "-h"
20
- puts "USAGE: sort-yaml FILES..."
21
- puts "USAGE: ... | sort-yaml"
22
- exit
23
- end
24
-
25
- inputs = ARGV
20
+ parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
26
21
 
27
- if inputs.empty?
28
- inputs = $stdin.each_line.to_a
22
+ abort parsed.help if parsed.options.help
29
23
 
30
- inputs =
31
- (File.exist?(inputs.first.strip) ? inputs.map(&:strip) : [inputs.join])
24
+ if parsed.options.version
25
+ abort File.read(File.expand_path("../../VERSION", __FILE__))
32
26
  end
33
27
 
34
- inputs.each do |input|
35
- content = File.exist?(input) ? File.read(input) : input
36
- yaml = sort_yaml(YAML.safe_load(content)).to_yaml
37
- File.exist?(input) ? File.write(input, yaml) : puts(yaml)
38
- end
28
+ inputs = parsed.arguments + parsed.files.map { |file| File.read(file) }
29
+ inputs = [$stdin.each_line.to_a.map(&:strip).join("\n")] if inputs.empty?
30
+
31
+ inputs.each { |input| puts sort_yaml(YAML.safe_load(input)).to_yaml }
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.4.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: yaml