kanrisuru 0.17.0 → 0.18.0

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: b3f695ef2a1f50c24f7e2c8a06a107202c72e36a19b4952a4af9fbe3bdda93d3
4
- data.tar.gz: e4ec5a94e1b24ff564fc46d909ddfd93bcb0d3e2baa916137c07740a896d8a6e
3
+ metadata.gz: bde6a8003df4dbe874a1b2471eb042b294fabc7e84d4146458fd3a1dbf4882ca
4
+ data.tar.gz: 4b2e3f0f35c62ee2286ad9aea4ae32cd7044418cc141c1abc176c5b017821c8d
5
5
  SHA512:
6
- metadata.gz: a02f65e7d962e2e02594bee48b8a8662bf29a936a02e9e938332340d695618bd92a2a3b6fc26c7324ecb0af236d6d6dc11475fd8205ee6cc77d97ff57f39cbdf
7
- data.tar.gz: 047b7235f156d77085a413d2af37ce09367d1eb68b33ae0b96b1e2a0ed8f79ba9b8111f3933e02dd37245393fd4c6333455407187fb62ba6ad524dfc42ec1f54
6
+ metadata.gz: b32475bde12456c03a3028f8ebbc6f792d59ad69b8014737d266d65ea4d4ba3208f864aa1eb8de58929abc8460e41971371fc6d4c3bc6c2d6e28db54c73fc9b5
7
+ data.tar.gz: a22f5af50adce7dc76504ba78fdddd000d08766e2115e4d092b12e8d44b5b76aa3e0f68cf6286c3344cde9d82520238ecd96b2e6b0b11384cc4ec859bbcebd2a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## Kanrisuru 0.18.0 (January 23, 2022) ##
2
+ * Add `history` command with test cases.
3
+
1
4
  ## Kanrisuru 0.17.0 (January 20, 2022) ##
2
5
  * Add `nproc` command with test cases.
3
6
 
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module System
6
+ def history(opts = {})
7
+ histfile = opts[:histfile] || '~/.bash_history'
8
+
9
+ command = Kanrisuru::Command.new("HISTFILE=#{histfile}; history -r; history")
10
+
11
+ if Kanrisuru::Util.present?(opts[:delete])
12
+ command.append_arg('-d', Kanrisuru::Util.array_join_string(opts[:delete], ' '))
13
+ elsif Kanrisuru::Util.present?(opts[:clear])
14
+ command.append_flag('-c')
15
+ elsif Kanrisuru::Util.present?(opts[:n])
16
+ command << opts[:n]
17
+ end
18
+
19
+ execute_shell(command)
20
+
21
+ Kanrisuru::Result.new(command) do |cmd|
22
+ return if Kanrisuru::Util.present?(opts[:delete]) || Kanrisuru::Util.present?(opts[:clear])
23
+
24
+ Parser::History.parse(cmd)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'commands/cpu_info'
4
4
  require_relative 'commands/free'
5
+ require_relative 'commands/history'
5
6
  require_relative 'commands/kernel_statistics'
6
7
  require_relative 'commands/kill'
7
8
  require_relative 'commands/last'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'parsers/kernel_statistics'
4
+ require_relative 'parsers/history'
4
5
  require_relative 'parsers/last'
5
6
  require_relative 'parsers/load_average'
6
7
  require_relative 'parsers/load_env'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module System
6
+ module Parser
7
+ class History
8
+ def self.parse(command)
9
+ lines = command.to_a
10
+ lines.map do |line|
11
+ line.split(/^\d+\s+/)[1]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.17.0'
4
+ VERSION = '0.18.0'
5
5
  end
@@ -43,6 +43,20 @@ RSpec.describe Kanrisuru::Core::System do
43
43
  end.to raise_error(ArgumentError)
44
44
  end
45
45
 
46
+ it 'prepares history command' do
47
+ expect_command(host.history, 'HISTFILE=~/.bash_history; history -r; history')
48
+ expect_command(host.history(histfile: '~/.history', n: 100),
49
+ 'HISTFILE=~/.history; history -r; history 100')
50
+ expect_command(host.history(clear: true),
51
+ 'HISTFILE=~/.bash_history; history -r; history -c')
52
+ expect_command(host.history(delete: 5),
53
+ 'HISTFILE=~/.bash_history; history -r; history -d 5')
54
+ expect_command(host.history(delete: [23, 30]),
55
+ 'HISTFILE=~/.bash_history; history -r; history -d 23 30')
56
+ expect_command(host.history(delete: '-7'),
57
+ 'HISTFILE=~/.bash_history; history -r; history -d -7')
58
+ end
59
+
46
60
  it 'prepares kernel_statistics command' do
47
61
  expect_command(host.kernel_statistics, 'cat /proc/stat')
48
62
  end
@@ -50,6 +50,12 @@ RSpec.shared_examples 'system' do |os_name, host_json, _spec_dir|
50
50
  expect(result.days).to be >= 0
51
51
  end
52
52
 
53
+ it 'gets history' do
54
+ result = host.history
55
+ expect(result).to be_success
56
+ expect(result.data).to be_instance_of(Array)
57
+ end
58
+
53
59
  it 'kills pids' do
54
60
  command = 'sleep 100000 > /dev/null 2>&1 &'
55
61
 
@@ -25,6 +25,7 @@ RSpec.describe Kanrisuru::Core::System do
25
25
  expect(host).to respond_to(:lscpu)
26
26
  expect(host).to respond_to(:load_average)
27
27
  expect(host).to respond_to(:free)
28
+ expect(host).to respond_to(:history)
28
29
  expect(host).to respond_to(:ps)
29
30
  expect(host).to respond_to(:kill)
30
31
  expect(host).to respond_to(:kernel_statistics)
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.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -307,6 +307,7 @@ files:
307
307
  - lib/kanrisuru/core/system/commands.rb
308
308
  - lib/kanrisuru/core/system/commands/cpu_info.rb
309
309
  - lib/kanrisuru/core/system/commands/free.rb
310
+ - lib/kanrisuru/core/system/commands/history.rb
310
311
  - lib/kanrisuru/core/system/commands/kernel_statistics.rb
311
312
  - lib/kanrisuru/core/system/commands/kill.rb
312
313
  - lib/kanrisuru/core/system/commands/last.rb
@@ -321,6 +322,7 @@ files:
321
322
  - lib/kanrisuru/core/system/commands/uptime.rb
322
323
  - lib/kanrisuru/core/system/commands/w.rb
323
324
  - lib/kanrisuru/core/system/parser.rb
325
+ - lib/kanrisuru/core/system/parsers/history.rb
324
326
  - lib/kanrisuru/core/system/parsers/kernel_statistics.rb
325
327
  - lib/kanrisuru/core/system/parsers/last.rb
326
328
  - lib/kanrisuru/core/system/parsers/load_average.rb