dorian-write 0.0.1 → 0.1.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/bin/write +16 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d850b22de422740f64c78f435b74c7f91b873f8ea9b2e122ce1eefdb89c9b66
4
- data.tar.gz: 111a9ade5a82df9df3a6d2944ee056dc98013619b365108395218ca7c15cb20e
3
+ metadata.gz: 31b3dd88831d0dc58281fb4cd7a34ab9cafab3fe1ab61012fe4427035c2a8d65
4
+ data.tar.gz: 4104bd56c35bbcdbb2d90feceb9c3f06b733748b443aa609298b4acc65c2f464
5
5
  SHA512:
6
- metadata.gz: 9a200ee7452b5a733a2b8228c5fa388efecf1a74cbe5912b120b8a9edd22ba06dcf67cdb2053c0980e8f54ef1f59235059d2f2d668f5bad5bdd6267ee18677b8
7
- data.tar.gz: 0f7e387c91cb8fbb826827c0b83f50e98af8d46603e3b9dbe5a513785032ec63767490b626f9be0dcf400ff6439f83aff1ff842ee745b0c03b3a14c81c7a5f7a
6
+ metadata.gz: 46869fee7ab4e6e9c2aa5eb68e4832c37b60cbaab0359bcc5c0b90a4a2856ef324b4ae34003f75fefbb2b44d0bf312ba471ae5a8efb24aa271b59f5be3fba2d0
7
+ data.tar.gz: 4fad4a9bd923a2bec84c9bf6c6c898db4bd139fb3b898319f46049c726ba77855218fc34542ba7fd5b24e635c7033c33c12def9e0675a87d78d42f8601f5ae7f
data/bin/write CHANGED
@@ -1,8 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- if ARGV.size != 1 || ARGV[0] == "--help" || ARGV[0] == "-h"
5
- abort "USAGE: ... | write FILE"
4
+ if ARGV.size < 1 || ARGV.first == "--help" || ARGV.first == "-h"
5
+ abort "USAGE: ... | write [-a|--append|-p|--prepend] FILES..."
6
6
  end
7
7
 
8
- File.write(ARGV.first, $stdin.each_line.to_a.map(&:strip).join("\n"))
8
+ PREPEND = ARGV.detect { |argv| argv == "-p" || argv == "--prepend" }
9
+ APPEND = ARGV.detect { |argv| argv == "-a" || argv == "--append" }
10
+ FILES = ARGV - [PREPEND] - [APPEND]
11
+ CONTENT = $stdin.each_line.to_a.map(&:strip).join("\n")
12
+
13
+ FILES.each do |file|
14
+ if APPEND
15
+ File.write(file, [File.read(file).strip, CONTENT].join("\n"))
16
+ elsif PREPEND
17
+ File.write(file, [CONTENT, File.read(file).strip].join("\n"))
18
+ else
19
+ File.write(file, CONTENT)
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-write
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.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-16 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Write to a file