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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/kanrisuru/core/system/commands/history.rb +29 -0
- data/lib/kanrisuru/core/system/commands.rb +1 -0
- data/lib/kanrisuru/core/system/parser.rb +1 -0
- data/lib/kanrisuru/core/system/parsers/history.rb +18 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/system_spec.rb +14 -0
- data/spec/support/shared_examples/integration/core/system.rb +6 -0
- data/spec/unit/core/system_spec.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bde6a8003df4dbe874a1b2471eb042b294fabc7e84d4146458fd3a1dbf4882ca
|
4
|
+
data.tar.gz: 4b2e3f0f35c62ee2286ad9aea4ae32cd7044418cc141c1abc176c5b017821c8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b32475bde12456c03a3028f8ebbc6f792d59ad69b8014737d266d65ea4d4ba3208f864aa1eb8de58929abc8460e41971371fc6d4c3bc6c2d6e28db54c73fc9b5
|
7
|
+
data.tar.gz: a22f5af50adce7dc76504ba78fdddd000d08766e2115e4d092b12e8d44b5b76aa3e0f68cf6286c3344cde9d82520238ecd96b2e6b0b11384cc4ec859bbcebd2a
|
data/CHANGELOG.md
CHANGED
@@ -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
|
@@ -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
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -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.
|
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-
|
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
|