kanrisuru 0.8.10 → 0.8.14

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: 8665542405d850b01c9c8623c200207c284925a0c14eb21a908711ebce6acf1e
4
- data.tar.gz: f52cdd4ecb4483d161494290da195270062865028a7ca02251a6de930f8477a1
3
+ metadata.gz: 1537cdde3ded7563e59018ddb94f1c05bb17ff486c87f6113eaa1800b6f7c338
4
+ data.tar.gz: 571b0fef3b4d780d3fac4f485f7f1b1dd14bd3c73253a7b5649ae7e86975fd81
5
5
  SHA512:
6
- metadata.gz: b7eeaf4fb3741e149ee9563d244934e72d9cc56bdfbcffb90bdddf57545c49b5a9736c93dca2a78c65b73d8848f84617ce7b4d323de81c214ed473764a401a94
7
- data.tar.gz: 834dc4092cfdd58e670b926eb3b77ed37d8a40cfb813aa8189f3ac718033d2de37d1ee23e59b530e7342dbd90c9807b35f95d194ac3239af4e9dfed2ee445875
6
+ metadata.gz: 2351ae7e335b61a1362c15a08540977c5d366ae2c441882f4feff32bc7939da71312dc5f380fa707a6c3cb187e81d413d558ae55e31e395d069e1a3c5e3f2a08
7
+ data.tar.gz: 2fbb6a9649eb2a67c46bc0a617cd22965738dfcbb092b4b99da588ae70518b4a0dfc79aa2da55c58d53f760170a5c33c844a86aae97f56eeed4628c735a65546
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## Kanrisuru 0.8.14 (October 8, 20201)
2
+ * Update `Kanrisuru::Remote::Cluster` instantiation method to use array splat instead of passing array directly.
3
+
4
+ ## Kanrisuru 0.8.13 (October 4, 20201)
5
+ * Fix `wc` command. Ensure result parsing is cast to integer values.
6
+
7
+ ## Kanrisuru 0.8.12 (October 4, 20201)
8
+ * Refactor `rmdir` command to only work on empty directories.
9
+
10
+ ## Kanrisuru 0.8.11 (October 1, 20201)
11
+ * Allow `Kanrisuru::Mode` as mode type option in mkdir method.
12
+
1
13
  ## Kanrisuru 0.8.10 (August 24, 20201)
2
14
  * Fix bug with rspec test case.
3
15
 
data/README.md CHANGED
@@ -48,7 +48,7 @@ result.path # => /home/ubuntu
48
48
 
49
49
  ### Cluster
50
50
  ```ruby
51
- cluster = Kanrisuru::Remote::Cluster.new([{
51
+ cluster = Kanrisuru::Remote::Cluster.new({
52
52
  host: 'host1', username: 'ubuntu', keys: ['~/.ssh/id_rsa']
53
53
  }, {
54
54
  host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']
@@ -72,7 +72,7 @@ host.execute(command)
72
72
  command.success? #=> true
73
73
  command.to_s #=> Linux
74
74
 
75
- cluster = Kanrisuru::Remote::Cluster.new([host, {host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']}])
75
+ cluster = Kanrisuru::Remote::Cluster.new(host, {host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']})
76
76
 
77
77
  cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', result: 'Linux'}
78
78
  ```
@@ -206,10 +206,19 @@ module Kanrisuru
206
206
  Kanrisuru::Result.new(command)
207
207
  end
208
208
 
209
- def rmdir(path)
210
- return false unless dir?(path)
209
+ def rmdir(paths, opts = {})
210
+ paths = [paths] if paths.instance_of?(String)
211
+ paths.each do |path|
212
+ raise ArgumentError, "Can't delete root path" if path == '/' || realpath(path).path == '/'
213
+ end
214
+
215
+ command = Kanrisuru::Command.new("rmdir #{paths.join(' ')}")
216
+ command.append_flag('--ignore-fail-on-non-empty', opts[:silent])
217
+ command.append_flag('--parents', opts[:parents])
218
+
219
+ execute_shell(command)
211
220
 
212
- rm(path, force: true, recursive: true)
221
+ Kanrisuru::Result.new(command)
213
222
  end
214
223
 
215
224
  def mkdir(path, opts = {})
@@ -219,7 +228,17 @@ module Kanrisuru
219
228
 
220
229
  command = Kanrisuru::Command.new("mkdir #{path}")
221
230
  command.append_flag('-p', opts[:silent])
222
- command.append_arg('-m', opts[:mode])
231
+
232
+ if Kanrisuru::Util.present?(opts[:mode])
233
+ mode = opts[:mode]
234
+ if mode.instance_of?(Kanrisuru::Mode)
235
+ mode = mode.numeric
236
+ elsif mode.instance_of?(String) && (mode.include?(',') || /[=+-]/.match(mode))
237
+ mode = Kanrisuru::Mode.new(mode).numeric
238
+ end
239
+
240
+ command.append_arg('-m', mode)
241
+ end
223
242
 
224
243
  execute_shell(command)
225
244
 
@@ -313,7 +332,7 @@ module Kanrisuru
313
332
  execute_shell(command)
314
333
 
315
334
  Kanrisuru::Result.new(command) do |cmd|
316
- items = cmd.to_a
335
+ items = cmd.to_s.split
317
336
  FileCount.new(items[0].to_i, items[1].to_i, items[2].to_i)
318
337
  end
319
338
  end
@@ -6,7 +6,7 @@ module Kanrisuru
6
6
  extend OsPackage::Collection
7
7
  include Enumerable
8
8
 
9
- def initialize(hosts)
9
+ def initialize(*hosts)
10
10
  @hosts = {}
11
11
  hosts.each do |host_opts|
12
12
  add_host(host_opts)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.8.10'
4
+ VERSION = '0.8.14'
5
5
  end
@@ -40,8 +40,8 @@ RSpec.describe Kanrisuru::Core::File do
40
40
  keys: [host_json['ssh_key']]
41
41
  )
42
42
 
43
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
44
- host.rmdir("#{host_json['home']}/extract-tar-files") if host.dir?("#{host_json['home']}/extract-tar-files")
43
+ host.rm("#{host_json['home']}/.kanrisuru_spec_files", force: true, recursive: true)
44
+ host.rm("#{host_json['home']}/extract-tar-files", force: true, recursive: true) if host.dir?("#{host_json['home']}/extract-tar-files")
45
45
  host.disconnect
46
46
  end
47
47
 
@@ -322,16 +322,44 @@ RSpec.describe Kanrisuru::Core::File do
322
322
  expect(host.empty_file?(path)).to eq(false)
323
323
  end
324
324
 
325
+ it 'removes directories' do
326
+ result = host.mkdir("#{spec_dir}/directory/1", silent: true)
327
+ expect(result).to be_success
328
+
329
+ result = host.mkdir("#{spec_dir}/directory/2", silent: true)
330
+ expect(result).to be_success
331
+
332
+ result = host.mkdir("#{spec_dir}/directory/3", silent: true)
333
+ expect(result).to be_success
334
+
335
+ result = host.rmdir(["#{spec_dir}/directory/1", "#{spec_dir}/directory/2"])
336
+ expect(result).to be_success
337
+
338
+ ## Can't delete non empty dir
339
+ result = host.rmdir("#{spec_dir}/directory")
340
+ expect(result).to be_failure
341
+
342
+ result = host.rmdir("#{spec_dir}/directory/3")
343
+ expect(result).to be_success
344
+ end
345
+
325
346
  it 'counts a file' do
326
347
  result = host.wc('/etc/hosts')
327
348
 
328
349
  expect(result.success?).to eq(true)
329
350
  expect(result).to respond_to(:lines, :words, :characters)
330
351
 
331
- lines = result.lines
332
- result = host.cat('/etc/hosts')
352
+ ## Need to remap data including newline chars to get byte size
353
+ data = host.cat('/etc/hosts').command.raw_result
354
+ doc = data.map(&:lines).flatten
355
+
356
+ lines = doc.length
357
+ words = doc.map(&:split).flatten
358
+ chars = doc.map(&:length).flatten
333
359
 
334
- expect(lines).to eq(result.to_a.length)
360
+ expect(result.lines).to eq(doc.length)
361
+ expect(result.words).to eq(words.length)
362
+ expect(result.characters).to eq(chars.sum)
335
363
  end
336
364
  end
337
365
  end
@@ -111,7 +111,7 @@ RSpec.describe Kanrisuru::OsPackage do
111
111
  host = Kanrisuru::Remote::Host.new(host: '127.0.0.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
112
112
  host2 = Kanrisuru::Remote::Host.new(host: 'localhost', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
113
113
 
114
- cluster = Kanrisuru::Remote::Cluster.new([host, host2])
114
+ cluster = Kanrisuru::Remote::Cluster.new(host, host2)
115
115
 
116
116
  expect(host).to respond_to(:tester)
117
117
  expect(host.tester).to eq('hello ubuntu')
@@ -125,7 +125,7 @@ RSpec.describe Kanrisuru::OsPackage do
125
125
  host = Kanrisuru::Remote::Host.new(host: '127.0.0.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
126
126
  host2 = Kanrisuru::Remote::Host.new(host: 'localhost', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
127
127
 
128
- cluster = Kanrisuru::Remote::Cluster.new([host, host2])
128
+ cluster = Kanrisuru::Remote::Cluster.new(host, host2)
129
129
 
130
130
  expect(host).to respond_to(:asdf)
131
131
  expect(host.asdf).to respond_to(:tester)
@@ -151,7 +151,7 @@ RSpec.describe Kanrisuru::OsPackage do
151
151
  host2 = Kanrisuru::Remote::Host.new(host: 'centos-host', username: 'centos', keys: ['~/.ssh/id_rsa'])
152
152
  host3 = Kanrisuru::Remote::Host.new(host: 'opensuse-host', username: 'opensuse', keys: ['~/.ssh/id_rsa'])
153
153
 
154
- cluster = Kanrisuru::Remote::Cluster.new([host1, host2, host3])
154
+ cluster = Kanrisuru::Remote::Cluster.new(host1, host2, host3)
155
155
 
156
156
  expect(host1).to respond_to(:output)
157
157
  expect(host2).to respond_to(:output)
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  RSpec.describe Kanrisuru::Remote::Cluster do
6
6
  context 'with ubuntu' do
7
7
  it 'gets hostname for cluster' do
8
- cluster = described_class.new([{
8
+ cluster = described_class.new({
9
9
  host: 'localhost',
10
10
  username: 'ubuntu',
11
11
  keys: ['~/.ssh/id_rsa']
@@ -13,7 +13,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
13
13
  host: '127.0.0.1',
14
14
  username: 'ubuntu',
15
15
  keys: ['~/.ssh/id_rsa']
16
- }])
16
+ })
17
17
 
18
18
  expect(cluster.hostname).to match([
19
19
  { host: 'localhost', result: 'ubuntu' },
@@ -24,7 +24,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
24
24
  end
25
25
 
26
26
  it 'can ping host cluster' do
27
- cluster = described_class.new([{
27
+ cluster = described_class.new({
28
28
  host: 'localhost',
29
29
  username: 'ubuntu',
30
30
  keys: ['~/.ssh/id_rsa']
@@ -32,7 +32,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
32
32
  host: '127.0.0.1',
33
33
  username: 'ubuntu',
34
34
  keys: ['~/.ssh/id_rsa']
35
- }])
35
+ })
36
36
 
37
37
  expect(cluster.ping?).to match([
38
38
  { host: 'localhost', result: true },
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.10
4
+ version: 0.8.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-24 00:00:00.000000000 Z
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec