kanrisuru 0.8.9 → 0.8.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1dfc7b4ed56b9054d2a9cffd137f21b47a992e76f89bc279911c619c9349b15
4
- data.tar.gz: ed85d4d847c5cdffc544dc93faf32552e6216e96da0ee9a4effa03f4f1cac08a
3
+ metadata.gz: f2465d4419a5fa15bc4ec736c6064e48386be6e130d4a934404b8a1b0f7eaaa0
4
+ data.tar.gz: 5441c0ae297aad2fdc7f08686eca97585793f747aaf92b32339da66c4343f3cf
5
5
  SHA512:
6
- metadata.gz: 1bfe2ce44a7a045ce622e3ca724fc9455e0efee19fd20235dda6befddeacd1c916604a41d053323879befe0762d37d9c41a87bd6221a564178973e9222cde6da
7
- data.tar.gz: 7130b94ddf938c126f3d4ef8f76f28298ff7f8abe169dbb9b4dd8ae384d334f6ccf17019e1aafb1c07ac2fcd0a0b5558aae36dd07f8f0523fc9721e7b5ed2e6b
6
+ metadata.gz: 328fdfb44f1d0b18f4bd1fb49ab54779fb464e3f8948a8600f2d2e5cdddfe8ac351fa4499ee0f981a8f12fd262bf1d7757f71d721dafbf447834c8d6ff17ac6f
7
+ data.tar.gz: 20c59fd7d9e2e57e356beecf55809c3cbb009fe5d0e8b5692088731ed6bac3665e1e88f6e162d6cda1b7874e8a9a30e30ef52a6c5572cdfbd33f4328ee402eda
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## Kanrisuru 0.8.13 (October 4, 20201)
2
+ * Fix `wc` command. Ensure result parsing is cast to integer values.
3
+
4
+ ## Kanrisuru 0.8.12 (October 4, 20201)
5
+ * Refactor `rmdir` command to only work on empty directories.
6
+
7
+ ## Kanrisuru 0.8.11 (October 1, 20201)
8
+ * Allow `Kanrisuru::Mode` as mode type option in mkdir method.
9
+
10
+ ## Kanrisuru 0.8.10 (August 24, 20201)
11
+ * Fix bug with rspec test case.
12
+
1
13
  ## Kanrisuru 0.8.9 (August 24, 2021)
2
14
  * Fix spelling error exception `ArgumentError` in `Kanrisuru::Mode` class.
3
15
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.8.9'
4
+ VERSION = '0.8.13'
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
 
@@ -69,7 +69,7 @@ RSpec.describe Kanrisuru::Core::File do
69
69
  expect(mode.to_i).to eq(0o744)
70
70
 
71
71
  expect {
72
- host.chmod(path, 600))
72
+ host.chmod(path, 600)
73
73
  }.to raise_error(ArgumentError)
74
74
  end
75
75
 
@@ -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
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.9
4
+ version: 0.8.13
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-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec