CmdShellMgr 0.1.0 → 0.1.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -5
- data/lib/CmdShellMgr/Command/command.rb +51 -0
- data/lib/CmdShellMgr/Command/commands.rb +102 -0
- data/lib/CmdShellMgr/DSL/dsl.rb +143 -0
- data/lib/CmdShellMgr/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06827d8b27d4b42c6c7f3ba6c2e80c8fc19f97f7
|
4
|
+
data.tar.gz: 2b9c414164c1844591aaa04e32caa06020d1782a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bac7be8a9c16f967e4164a074958a08b4016dfd36ea81d6d34b69a7c8138ccba05349b793089d45f09a68c9f4bcb8c57dedf4d03da883a9c3f3bda478ff208e
|
7
|
+
data.tar.gz: c54d3a48252ccd8f4651f620e4114496c7683e59d8cba15ef1c6d65dd4464c21ea5de2e8ffd7a270a81958313321321ab5daa2a930101fe962efd7eb6f54f24a
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# CmdShellMgr
|
2
2
|
|
3
|
-
|
3
|
+
CmdShellMgr provides a DSL, domain specific language, container to manage
|
4
|
+
commands. Commands are managed by defining, executing, and accessing
|
5
|
+
their results from a preferred framework, test script, or utility.
|
4
6
|
|
5
|
-
|
7
|
+
## Use Case
|
8
|
+
Test automation frameworks, with CmdShellMgr, can easily be extended to
|
9
|
+
execute external commands and manage those results.
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
13
|
```ruby
|
12
14
|
gem 'CmdShellMgr'
|
13
15
|
```
|
@@ -22,7 +24,44 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
|
28
|
+
|
29
|
+
## Examples (ScoutUI YAML)
|
30
|
+
|
31
|
+
page:
|
32
|
+
name: Run ls
|
33
|
+
action: loadcommand
|
34
|
+
command:
|
35
|
+
- echo "Hello World"
|
36
|
+
- java -jar Tools.jar <.......>
|
37
|
+
id: DO Linux ls
|
38
|
+
---
|
39
|
+
page:
|
40
|
+
name: run ls
|
41
|
+
action: execute(DO Linux ls)
|
42
|
+
---
|
43
|
+
page:
|
44
|
+
name: Run a BASH Script
|
45
|
+
action: loadcommand
|
46
|
+
command: /tmp/abc.sh
|
47
|
+
id: CREATE_Foo
|
48
|
+
|
49
|
+
---
|
50
|
+
|
51
|
+
page:
|
52
|
+
name: do something
|
53
|
+
action: execute(CREATE_Foo)
|
54
|
+
parms:
|
55
|
+
- abc
|
56
|
+
- 123
|
57
|
+
- EFG
|
58
|
+
- ${userid}
|
59
|
+
|
60
|
+
---
|
61
|
+
page:
|
62
|
+
name: blah
|
63
|
+
action: type(#username, getResult(CREATE_Foo))
|
64
|
+
---
|
26
65
|
|
27
66
|
## Development
|
28
67
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module CmdShellMgr
|
4
|
+
|
5
|
+
|
6
|
+
class Command
|
7
|
+
|
8
|
+
attr_accessor :debug
|
9
|
+
attr_accessor :cmd
|
10
|
+
attr_accessor :results
|
11
|
+
attr_accessor :exitStatus
|
12
|
+
|
13
|
+
def initialize(_c=nil)
|
14
|
+
@debug=true
|
15
|
+
@exitStatus=nil
|
16
|
+
@results=nil
|
17
|
+
@cmd=_c
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def execute(opts=nil)
|
22
|
+
@results=nil
|
23
|
+
|
24
|
+
# if @cmd.match(/.*\.(sh|ksh|csh)\s*$/i)
|
25
|
+
# puts " execute script #{@cmd} #{opts.to_s}" if @debug
|
26
|
+
# @results = %x[ #{@cmd} #{opts.to_s} ]
|
27
|
+
# else
|
28
|
+
@results = %x[ #{@cmd} #{opts.to_s} ]
|
29
|
+
# end
|
30
|
+
@exitStatus = $?.exitstatus
|
31
|
+
|
32
|
+
if @debug
|
33
|
+
puts __FILE__ + (__LINE__).to_s + " results => #{@results}"
|
34
|
+
puts __FILE__ + (__LINE__).to_s + " exist => #{@exitStatus}"
|
35
|
+
end
|
36
|
+
|
37
|
+
@exitStatus
|
38
|
+
end
|
39
|
+
|
40
|
+
def exitStatus
|
41
|
+
@exitStatus
|
42
|
+
end
|
43
|
+
|
44
|
+
def results
|
45
|
+
@results
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
module CmdShellMgr
|
5
|
+
|
6
|
+
|
7
|
+
class Commands
|
8
|
+
|
9
|
+
attr_reader :debug
|
10
|
+
attr_accessor :queue
|
11
|
+
|
12
|
+
|
13
|
+
def initialize()
|
14
|
+
@debug=false
|
15
|
+
@queue=[]
|
16
|
+
end
|
17
|
+
|
18
|
+
def count
|
19
|
+
length
|
20
|
+
end
|
21
|
+
def size
|
22
|
+
length
|
23
|
+
end
|
24
|
+
def length
|
25
|
+
@queue.length
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(_id, _cmd)
|
29
|
+
|
30
|
+
if _cmd.is_a?(String)
|
31
|
+
@queue << { :id => _id, :cmd => CmdShellMgr::Command.new(_cmd) }
|
32
|
+
else
|
33
|
+
@queue << { :id => _id, :cmd => _cmd }
|
34
|
+
end
|
35
|
+
|
36
|
+
@queue.last()
|
37
|
+
end
|
38
|
+
|
39
|
+
def _execute(cmd)
|
40
|
+
rc=0
|
41
|
+
if cmd.is_a?(Hash) && cmd.has_key?(:cmd) && cmd.has_key?(:id)
|
42
|
+
rc += cmd[:cmd].execute().to_i
|
43
|
+
end
|
44
|
+
|
45
|
+
rc
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
def execute(id=nil)
|
51
|
+
|
52
|
+
exitStatus=0
|
53
|
+
rc=nil
|
54
|
+
|
55
|
+
if id.nil?
|
56
|
+
@queue.each do |_cmd|
|
57
|
+
|
58
|
+
puts __FILE__ + (__LINE__).to_s + " execute command #{_cmd[:id]}" if @debug
|
59
|
+
rc=_cmd[:cmd].execute()
|
60
|
+
end
|
61
|
+
else
|
62
|
+
hits = @queue.select { |cmd| cmd[:id]==id }
|
63
|
+
hits.each do |h|
|
64
|
+
puts __FILE__ + (__LINE__).to_s + " #{h}" if @debug
|
65
|
+
_execute(h)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
rc
|
70
|
+
end
|
71
|
+
|
72
|
+
def exitStatus(_id)
|
73
|
+
puts __FILE__ + (__LINE__).to_s + " results(#{_id})" if @debug
|
74
|
+
rc=""
|
75
|
+
hits = @queue.select { |cmd| cmd[:id]==_id }
|
76
|
+
hits.each do |h|
|
77
|
+
|
78
|
+
puts __FILE__ + (__LINE__).to_s + " results : #{h[:cmd].exitStatus}" if @debug
|
79
|
+
rc << h[:cmd].exitStatus.to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
rc
|
83
|
+
end
|
84
|
+
|
85
|
+
def results(_id)
|
86
|
+
puts __FILE__ + (__LINE__).to_s + " results(#{_id})" if @debug
|
87
|
+
rc=""
|
88
|
+
hits = @queue.select { |cmd| cmd[:id]==_id }
|
89
|
+
hits.each do |h|
|
90
|
+
|
91
|
+
puts __FILE__ + (__LINE__).to_s + " results : #{h[:cmd].results}" if @debug
|
92
|
+
rc << h[:cmd].results.to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
rc
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
end
|
102
|
+
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module CmdShellMgr
|
4
|
+
|
5
|
+
|
6
|
+
class DSL
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
DSL_LIST=[
|
10
|
+
{ id: 'add', regex: Regexp.new(/^\s*(add|command)\s*\(\s*(?<id>.*)?,\s*(?<cmd>.*)\s*\)\s*$/i)},
|
11
|
+
{ id: 'execute', regex: Regexp.new(/^\s*execute\s*\(\s*(?<id>.*)?\)\s*$/i) },
|
12
|
+
{ id: 'getResult', regex: Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*$/i) },
|
13
|
+
{ id: 'matches', regex: Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*\.matches\s*\(\s*\/(?<regex>.*)?\/\s*\)$/i) },
|
14
|
+
{ id: 'capture', regex: Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*\.capture\s*\(\s*\/(?<regex>.*)?\/\s*\)$/i) },
|
15
|
+
{ id: 'status', regex: Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*\.exitStatus\s*$/i) }
|
16
|
+
]
|
17
|
+
|
18
|
+
attr_accessor :queue
|
19
|
+
attr_accessor :debug
|
20
|
+
|
21
|
+
def validCmd?(_cmd)
|
22
|
+
DSL_LIST.each do |c|
|
23
|
+
_r = c[:regex]
|
24
|
+
if _cmd.match(_r)
|
25
|
+
return c
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize()
|
33
|
+
@debug=false
|
34
|
+
@queue = CmdShellMgr::Commands.new()
|
35
|
+
end
|
36
|
+
|
37
|
+
def count
|
38
|
+
@queue.length
|
39
|
+
end
|
40
|
+
|
41
|
+
def cmd(opts)
|
42
|
+
|
43
|
+
rc=nil
|
44
|
+
cmdObj=nil
|
45
|
+
_cmd=nil
|
46
|
+
|
47
|
+
|
48
|
+
if opts.has_key?(:cmd)
|
49
|
+
_cmd=opts[:cmd]
|
50
|
+
else
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "CMD => #{_cmd}" if @debug
|
55
|
+
|
56
|
+
begin
|
57
|
+
cmdReg = Regexp.new(/^\s*(add|command)\s*\(\s*(?<id>.*)?,\s*(?<cmd>.*)\s*\)\s*$/i)
|
58
|
+
executeIdReg = Regexp.new(/^\s*execute\s*\(\s*(?<id>.*)?\)\s*$/i)
|
59
|
+
getResultsReg = Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*$/i)
|
60
|
+
getResultsMatchesReg = Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*\.matches\s*\(\s*\/(?<regex>.*)?\/\s*\)$/i)
|
61
|
+
getResultsCaptureReg = Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*\.capture\s*\(\s*\/(?<regex>.*)?\/\s*\)$/i)
|
62
|
+
getResultsStatusReg = Regexp.new(/^\s*getResult[s]*\s*\(\s*(?<id>.*)?\)\s*\.exitStatus\s*$/i)
|
63
|
+
|
64
|
+
cmdObj = _cmd.match(cmdReg)
|
65
|
+
|
66
|
+
if cmdObj
|
67
|
+
|
68
|
+
puts __FILE__ + (__LINE__).to_s + " cmdObj => #{cmdObj.class}" if @debug # MatchData
|
69
|
+
|
70
|
+
cmd = CmdShellMgr::Command.new(cmdObj[:cmd]);
|
71
|
+
puts __FILE__ + (__LINE__).to_s + " cmd ==> #{cmd}" if @debug
|
72
|
+
|
73
|
+
rc=@queue.add(cmdObj[:id], cmd)
|
74
|
+
|
75
|
+
elsif _cmd.match(executeIdReg)
|
76
|
+
|
77
|
+
cmdObj = _cmd.match(executeIdReg)
|
78
|
+
puts __FILE__ + (__LINE__).to_s + " exe => #{cmdObj[:id]}" if @debug
|
79
|
+
|
80
|
+
rc=@queue.execute(cmdObj[:id])
|
81
|
+
|
82
|
+
puts __FILE__ + (__LINE__).to_s + " executeResults => #{rc}"
|
83
|
+
|
84
|
+
elsif _cmd.match(getResultsStatusReg)
|
85
|
+
cmdObj=_cmd.match(getResultsStatusReg)
|
86
|
+
rc = @queue.exitStatus(cmdObj[:id])
|
87
|
+
puts __FILE__ + (__LINE__).to_s + " exitStatus(#{_cmd}) : #{rc}" if @debug
|
88
|
+
|
89
|
+
|
90
|
+
elsif _cmd.match(getResultsMatchesReg)
|
91
|
+
cmdObj = _cmd.match(getResultsMatchesReg)
|
92
|
+
_result = @queue.results(cmdObj[:id])
|
93
|
+
regex = cmdObj[:regex]
|
94
|
+
|
95
|
+
rc=false
|
96
|
+
|
97
|
+
if _result.is_a?(String)
|
98
|
+
m=_result.match(/#{regex.to_s}/m)
|
99
|
+
rc = m.is_a?(MatchData) && m.size > 0
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
elsif _cmd.match(getResultsCaptureReg)
|
104
|
+
cmdObj = _cmd.match(getResultsCaptureReg)
|
105
|
+
_result=@queue.results(cmdObj[:id])
|
106
|
+
regex = cmdObj[:regex]
|
107
|
+
puts __FILE__ + (__LINE__).to_s + "RESULTS.Capture => #{_result.class} with #{regex}" if @debug
|
108
|
+
|
109
|
+
m=nil
|
110
|
+
if _result.is_a?(String)
|
111
|
+
m = _result.match(/#{regex.to_s}/m)
|
112
|
+
|
113
|
+
puts __FILE__ + (__LINE__).to_s + " m => #{m.class}" if @debug
|
114
|
+
|
115
|
+
if m.is_a?(MatchData) && m.size > 0
|
116
|
+
puts __FILE__ + (__LINE__).to_s + " ====> #{m[1]}" if @debug
|
117
|
+
rc=m[1]
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
elsif _cmd.match(getResultsReg)
|
123
|
+
|
124
|
+
cmdObj=_cmd.match(getResultsReg)
|
125
|
+
rc=@queue.results(cmdObj[:id])
|
126
|
+
puts __FILE__ + (__LINE__).to_s + "RESULTS => #{rc}" if @debug
|
127
|
+
|
128
|
+
else
|
129
|
+
puts __FILE__ + (__LINE__).to_s + " Unknown command: #{_cmd}"
|
130
|
+
end
|
131
|
+
|
132
|
+
rescue RegexpError => ex
|
133
|
+
puts __FILE__ + (__LINE__).to_s + " #{ex.class} : #{_cmd}"
|
134
|
+
end
|
135
|
+
|
136
|
+
rc
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
end
|
data/lib/CmdShellMgr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CmdShellMgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.1.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kim, Peter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,9 @@ files:
|
|
73
73
|
- bin/console
|
74
74
|
- bin/setup
|
75
75
|
- lib/CmdShellMgr.rb
|
76
|
+
- lib/CmdShellMgr/Command/command.rb
|
77
|
+
- lib/CmdShellMgr/Command/commands.rb
|
78
|
+
- lib/CmdShellMgr/DSL/dsl.rb
|
76
79
|
- lib/CmdShellMgr/version.rb
|
77
80
|
homepage: https://github.com/h20draoon
|
78
81
|
licenses:
|
@@ -89,9 +92,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
92
|
version: '0'
|
90
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
94
|
requirements:
|
92
|
-
- - "
|
95
|
+
- - ">"
|
93
96
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
97
|
+
version: 1.3.1
|
95
98
|
requirements: []
|
96
99
|
rubyforge_project:
|
97
100
|
rubygems_version: 2.6.2
|