gloo-lang 0.9.4 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/gloo-lang.gemspec +1 -0
- data/lib/VERSION +1 -1
- data/lib/gloo_lang/app/args.rb +0 -1
- data/lib/gloo_lang/app/engine.rb +10 -37
- data/lib/gloo_lang/app/help.rb +2 -41
- data/lib/gloo_lang/app/log.rb +8 -10
- data/lib/gloo_lang/app/platform.rb +75 -0
- data/lib/gloo_lang/app/settings.rb +36 -13
- data/lib/gloo_lang/objs/basic/container.rb +1 -12
- data/lib/gloo_lang/objs/basic/text.rb +2 -10
- data/lib/gloo_lang/objs/data/markdown.rb +2 -7
- data/lib/gloo_lang/objs/data/table.rb +1 -29
- data/lib/gloo_lang/verbs/show.rb +3 -2
- metadata +22 -22
- data/lib/gloo_lang/objs/cli/banner.rb +0 -108
- data/lib/gloo_lang/objs/cli/bar.rb +0 -133
- data/lib/gloo_lang/objs/cli/colorize.rb +0 -73
- data/lib/gloo_lang/objs/cli/confirm.rb +0 -96
- data/lib/gloo_lang/objs/cli/menu.rb +0 -206
- data/lib/gloo_lang/objs/cli/menu_item.rb +0 -95
- data/lib/gloo_lang/objs/cli/pastel.rb +0 -97
- data/lib/gloo_lang/objs/cli/prompt.rb +0 -110
- data/lib/gloo_lang/objs/cli/select.rb +0 -126
- data/lib/gloo_lang/objs/data/mysql.rb +0 -192
- data/lib/gloo_lang/objs/data/sqlite.rb +0 -159
- data/lib/gloo_lang/objs/dev/git.rb +0 -140
- data/lib/gloo_lang/objs/dev/stats.rb +0 -120
- data/lib/gloo_lang/objs/snd/play.rb +0 -48
- data/lib/gloo_lang/objs/snd/say.rb +0 -98
- data/lib/gloo_lang/objs/system/file_handle.rb +0 -138
- data/lib/gloo_lang/objs/system/ssh_exec.rb +0 -126
- data/lib/gloo_lang/objs/system/system.rb +0 -136
- data/lib/gloo_lang/verbs/alert.rb +0 -79
- data/lib/gloo_lang/verbs/beep.rb +0 -40
- data/lib/gloo_lang/verbs/cls.rb +0 -37
@@ -1,140 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An object that interacts with a git repository
|
5
|
-
#
|
6
|
-
|
7
|
-
module GlooLang
|
8
|
-
module Objs
|
9
|
-
class Git < GlooLang::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'git_repo'.freeze
|
12
|
-
KEYWORD_SHORT = 'git'.freeze
|
13
|
-
|
14
|
-
#
|
15
|
-
# The name of the object type.
|
16
|
-
#
|
17
|
-
def self.typename
|
18
|
-
return KEYWORD
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# The short name of the object type.
|
23
|
-
#
|
24
|
-
def self.short_typename
|
25
|
-
return KEYWORD_SHORT
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Get the path to the git repo (locally).
|
30
|
-
#
|
31
|
-
def path_value
|
32
|
-
return value
|
33
|
-
end
|
34
|
-
|
35
|
-
# ---------------------------------------------------------------------
|
36
|
-
# Messages
|
37
|
-
# ---------------------------------------------------------------------
|
38
|
-
|
39
|
-
#
|
40
|
-
# Get a list of message names that this object receives.
|
41
|
-
#
|
42
|
-
def self.messages
|
43
|
-
actions = %w[validate commit get_branch review]
|
44
|
-
changes = %w[check_changes get_changes]
|
45
|
-
return super + changes + actions
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# Get the current working branch.
|
50
|
-
#
|
51
|
-
def msg_get_branch
|
52
|
-
branch = ''
|
53
|
-
path = path_value
|
54
|
-
if path_is_dir?( path )
|
55
|
-
branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
|
56
|
-
branch = branch.strip
|
57
|
-
end
|
58
|
-
|
59
|
-
$engine.heap.it.set_to branch
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Review pending changes.
|
64
|
-
#
|
65
|
-
def msg_review
|
66
|
-
$log.debug 'Reviewing pending changes'
|
67
|
-
cmd = "cd #{path_value}; git diff"
|
68
|
-
$log.debug cmd
|
69
|
-
system cmd
|
70
|
-
end
|
71
|
-
|
72
|
-
#
|
73
|
-
# Commit pending changes.
|
74
|
-
#
|
75
|
-
def msg_commit
|
76
|
-
msg = 'Commit'
|
77
|
-
path = path_value
|
78
|
-
if path_is_dir?( path )
|
79
|
-
if @params&.token_count&.positive?
|
80
|
-
expr = GlooLang::Expr::Expression.new( @params.tokens )
|
81
|
-
msg = expr.evaluate
|
82
|
-
end
|
83
|
-
branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
|
84
|
-
branch = branch.strip
|
85
|
-
add = 'git add .'
|
86
|
-
cmt = 'git commit -m '
|
87
|
-
psh = 'git push origin '
|
88
|
-
`cd #{path};#{add};#{cmt}"#{msg}";#{psh}#{branch}`
|
89
|
-
end
|
90
|
-
$engine.heap.it.set_to msg
|
91
|
-
end
|
92
|
-
|
93
|
-
#
|
94
|
-
# Get the pending changes.
|
95
|
-
#
|
96
|
-
def msg_get_changes
|
97
|
-
path = path_value
|
98
|
-
result = `cd #{path}; git status -s` if path_is_dir?( path )
|
99
|
-
result ||= ''
|
100
|
-
$engine.heap.it.set_to result
|
101
|
-
end
|
102
|
-
|
103
|
-
#
|
104
|
-
# Is the given path non nil and is it a directory?
|
105
|
-
#
|
106
|
-
def path_is_dir?( path )
|
107
|
-
return path && File.directory?( path )
|
108
|
-
end
|
109
|
-
|
110
|
-
#
|
111
|
-
# Check to see if the repo has changes.
|
112
|
-
#
|
113
|
-
def msg_check_changes
|
114
|
-
result = false
|
115
|
-
path = path_value
|
116
|
-
if path_is_dir?( path )
|
117
|
-
data = `cd #{path}; git status -s`
|
118
|
-
result = true unless data.strip.empty?
|
119
|
-
end
|
120
|
-
|
121
|
-
$engine.heap.it.set_to result
|
122
|
-
end
|
123
|
-
|
124
|
-
#
|
125
|
-
# Check to make sure this is a valide git repo.
|
126
|
-
#
|
127
|
-
def msg_validate
|
128
|
-
result = false
|
129
|
-
path = path_value
|
130
|
-
if path_is_dir?( path )
|
131
|
-
pn = File.join( path, '.git' )
|
132
|
-
result = File.exist? pn
|
133
|
-
end
|
134
|
-
|
135
|
-
$engine.heap.it.set_to result
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Get statistics about a development project.
|
5
|
-
#
|
6
|
-
|
7
|
-
module GlooLang
|
8
|
-
module Objs
|
9
|
-
class Stats < GlooLang::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'stats'.freeze
|
12
|
-
KEYWORD_SHORT = 'stat'.freeze
|
13
|
-
FOLDER = 'folder'.freeze
|
14
|
-
TYPES = 'types'.freeze
|
15
|
-
SKIP = 'skip'.freeze
|
16
|
-
|
17
|
-
#
|
18
|
-
# The name of the object type.
|
19
|
-
#
|
20
|
-
def self.typename
|
21
|
-
return KEYWORD
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# The short name of the object type.
|
26
|
-
#
|
27
|
-
def self.short_typename
|
28
|
-
return KEYWORD_SHORT
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the path to the git repo (locally).
|
33
|
-
#
|
34
|
-
def path_value
|
35
|
-
o = find_child FOLDER
|
36
|
-
return o ? o.value : nil
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# The code file types to count.
|
41
|
-
#
|
42
|
-
def types_value
|
43
|
-
o = find_child TYPES
|
44
|
-
return o ? o.value : ''
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Get the list of files and folders to skip.
|
49
|
-
#
|
50
|
-
def skip_list
|
51
|
-
o = find_child SKIP
|
52
|
-
val = o ? o.value : ''
|
53
|
-
return val.split ' '
|
54
|
-
end
|
55
|
-
|
56
|
-
# ---------------------------------------------------------------------
|
57
|
-
# Children
|
58
|
-
# ---------------------------------------------------------------------
|
59
|
-
|
60
|
-
#
|
61
|
-
# Does this object have children to add when an object
|
62
|
-
# is created in interactive mode?
|
63
|
-
# This does not apply during obj load, etc.
|
64
|
-
#
|
65
|
-
def add_children_on_create?
|
66
|
-
return true
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# Add children to this object.
|
71
|
-
# This is used by containers to add children needed
|
72
|
-
# for default configurations.
|
73
|
-
#
|
74
|
-
def add_default_children
|
75
|
-
fac = $engine.factory
|
76
|
-
fac.create_file FOLDER, '', self
|
77
|
-
fac.create_string TYPES, '', self
|
78
|
-
fac.create_can SKIP, self
|
79
|
-
end
|
80
|
-
|
81
|
-
# ---------------------------------------------------------------------
|
82
|
-
# Messages
|
83
|
-
# ---------------------------------------------------------------------
|
84
|
-
|
85
|
-
#
|
86
|
-
# Get a list of message names that this object receives.
|
87
|
-
#
|
88
|
-
def self.messages
|
89
|
-
all = %w[show_all]
|
90
|
-
more = %w[show_busy_folders show_types]
|
91
|
-
return super + all + more
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# Show all project stats.
|
96
|
-
#
|
97
|
-
def msg_show_all
|
98
|
-
o = GlooLang::Utils::Stats.new( path_value, types_value, skip_list )
|
99
|
-
o.show_all
|
100
|
-
end
|
101
|
-
|
102
|
-
#
|
103
|
-
# Show file types.
|
104
|
-
#
|
105
|
-
def msg_show_types
|
106
|
-
o = GlooLang::Utils::Stats.new( path_value, types_value, skip_list )
|
107
|
-
o.file_types
|
108
|
-
end
|
109
|
-
|
110
|
-
#
|
111
|
-
# Show busy folders: those with the most files.
|
112
|
-
#
|
113
|
-
def msg_show_busy_folders
|
114
|
-
o = GlooLang::Utils::Stats.new( path_value, types_value, skip_list )
|
115
|
-
o.busy_folders
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Play an audio file (MP3).
|
5
|
-
#
|
6
|
-
|
7
|
-
module GlooLang
|
8
|
-
module Objs
|
9
|
-
class Play < GlooLang::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'play'.freeze
|
12
|
-
KEYWORD_SHORT = 'play'.freeze
|
13
|
-
|
14
|
-
#
|
15
|
-
# The name of the object type.
|
16
|
-
#
|
17
|
-
def self.typename
|
18
|
-
return KEYWORD
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# The short name of the object type.
|
23
|
-
#
|
24
|
-
def self.short_typename
|
25
|
-
return KEYWORD_SHORT
|
26
|
-
end
|
27
|
-
|
28
|
-
# ---------------------------------------------------------------------
|
29
|
-
# Messages
|
30
|
-
# ---------------------------------------------------------------------
|
31
|
-
|
32
|
-
#
|
33
|
-
# Get a list of message names that this object receives.
|
34
|
-
#
|
35
|
-
def self.messages
|
36
|
-
return super + [ 'run' ]
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# Play the audio file.
|
41
|
-
#
|
42
|
-
def msg_run
|
43
|
-
system "afplay #{value}"
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Wrapper for the 'say something' function on the Mac.
|
5
|
-
#
|
6
|
-
require 'erb'
|
7
|
-
|
8
|
-
module GlooLang
|
9
|
-
module Objs
|
10
|
-
class Say < GlooLang::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'say'.freeze
|
13
|
-
KEYWORD_SHORT = 'say'.freeze
|
14
|
-
VOICE = 'voice'.freeze
|
15
|
-
MSG = 'message'.freeze
|
16
|
-
DEFAULT_MSG = 'talk to me'.freeze
|
17
|
-
|
18
|
-
#
|
19
|
-
# The name of the object type.
|
20
|
-
#
|
21
|
-
def self.typename
|
22
|
-
return KEYWORD
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# The short name of the object type.
|
27
|
-
#
|
28
|
-
def self.short_typename
|
29
|
-
return KEYWORD_SHORT
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# Get the voice to use.
|
34
|
-
#
|
35
|
-
def voice_value
|
36
|
-
v = find_child VOICE
|
37
|
-
return nil unless v
|
38
|
-
|
39
|
-
return v.value
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Get the message to speak.
|
44
|
-
#
|
45
|
-
def msg_value
|
46
|
-
o = find_child MSG
|
47
|
-
return nil unless o
|
48
|
-
|
49
|
-
return o.value
|
50
|
-
end
|
51
|
-
|
52
|
-
# ---------------------------------------------------------------------
|
53
|
-
# Children
|
54
|
-
# ---------------------------------------------------------------------
|
55
|
-
|
56
|
-
#
|
57
|
-
# Does this object have children to add when an object
|
58
|
-
# is created in interactive mode?
|
59
|
-
# This does not apply during obj load, etc.
|
60
|
-
#
|
61
|
-
def add_children_on_create?
|
62
|
-
return true
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Add children to this object.
|
67
|
-
# This is used by containers to add children needed
|
68
|
-
# for default configurations.
|
69
|
-
#
|
70
|
-
def add_default_children
|
71
|
-
fac = $engine.factory
|
72
|
-
fac.create_string VOICE, '', self
|
73
|
-
fac.create_string MSG, DEFAULT_MSG, self
|
74
|
-
end
|
75
|
-
|
76
|
-
# ---------------------------------------------------------------------
|
77
|
-
# Messages
|
78
|
-
# ---------------------------------------------------------------------
|
79
|
-
|
80
|
-
#
|
81
|
-
# Get a list of message names that this object receives.
|
82
|
-
#
|
83
|
-
def self.messages
|
84
|
-
return super + [ 'run' ]
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
# Have the computer 'speak' the message.
|
89
|
-
#
|
90
|
-
def msg_run
|
91
|
-
v = voice_value.empty? ? '' : "-v '#{voice_value}'"
|
92
|
-
cmd = "say #{v} '#{msg_value}'"
|
93
|
-
system cmd
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An object that points to a file in the system.
|
5
|
-
#
|
6
|
-
require 'tty-pager'
|
7
|
-
|
8
|
-
module GlooLang
|
9
|
-
module Objs
|
10
|
-
class FileHandle < GlooLang::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'file'.freeze
|
13
|
-
KEYWORD_SHORT = 'dir'.freeze
|
14
|
-
|
15
|
-
#
|
16
|
-
# The name of the object type.
|
17
|
-
#
|
18
|
-
def self.typename
|
19
|
-
return KEYWORD
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# The short name of the object type.
|
24
|
-
#
|
25
|
-
def self.short_typename
|
26
|
-
return KEYWORD_SHORT
|
27
|
-
end
|
28
|
-
|
29
|
-
# ---------------------------------------------------------------------
|
30
|
-
# Messages
|
31
|
-
# ---------------------------------------------------------------------
|
32
|
-
|
33
|
-
#
|
34
|
-
# Get a list of message names that this object receives.
|
35
|
-
#
|
36
|
-
def self.messages
|
37
|
-
basic = %w[read write]
|
38
|
-
checks = %w[check_exists check_is_file check_is_dir]
|
39
|
-
search = %w[find_match]
|
40
|
-
show = %w[show page open]
|
41
|
-
return super + basic + show + checks + search
|
42
|
-
end
|
43
|
-
|
44
|
-
#
|
45
|
-
# Open the file in the default application for the file type.
|
46
|
-
#
|
47
|
-
def msg_open
|
48
|
-
return unless value && File.exist?( value )
|
49
|
-
|
50
|
-
cmd = GlooLang::Core::GlooSystem.open_for_platform
|
51
|
-
cmd_with_param = "#{cmd} \"#{value}\""
|
52
|
-
`#{cmd_with_param}`
|
53
|
-
end
|
54
|
-
|
55
|
-
#
|
56
|
-
# Show the contents of the file, paginated.
|
57
|
-
#
|
58
|
-
def msg_page
|
59
|
-
return unless value && File.file?( value )
|
60
|
-
|
61
|
-
pager = TTY::Pager.new
|
62
|
-
pager.page( path: value )
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Show the contents of the file.
|
67
|
-
#
|
68
|
-
def msg_show
|
69
|
-
return unless value && File.file?( value )
|
70
|
-
|
71
|
-
puts File.read( value )
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# Read the contents of the file into the object.
|
76
|
-
#
|
77
|
-
def msg_read
|
78
|
-
return unless value && File.file?( value )
|
79
|
-
|
80
|
-
data = File.read( value )
|
81
|
-
if @params&.token_count&.positive?
|
82
|
-
pn = GlooLang::Core::Pn.new @params.first
|
83
|
-
o = pn.resolve
|
84
|
-
o.set_value data
|
85
|
-
else
|
86
|
-
$engine.heap.it.set_to data
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Write the given data out to the file.
|
92
|
-
#
|
93
|
-
def msg_write
|
94
|
-
data = ''
|
95
|
-
return unless value
|
96
|
-
|
97
|
-
if @params&.token_count&.positive?
|
98
|
-
expr = GlooLang::Expr::Expression.new( @params.tokens )
|
99
|
-
data = expr.evaluate
|
100
|
-
end
|
101
|
-
File.write( value, data )
|
102
|
-
end
|
103
|
-
|
104
|
-
#
|
105
|
-
# Check to see if the file exists.
|
106
|
-
#
|
107
|
-
def msg_check_exists
|
108
|
-
result = File.exist? value
|
109
|
-
$engine.heap.it.set_to result
|
110
|
-
end
|
111
|
-
|
112
|
-
#
|
113
|
-
# Check to see if the file is a file.
|
114
|
-
#
|
115
|
-
def msg_check_is_file
|
116
|
-
result = File.file? value
|
117
|
-
$engine.heap.it.set_to result
|
118
|
-
end
|
119
|
-
|
120
|
-
#
|
121
|
-
# Check to see if the file is a directory.
|
122
|
-
#
|
123
|
-
def msg_check_is_dir
|
124
|
-
result = File.directory? value
|
125
|
-
$engine.heap.it.set_to result
|
126
|
-
end
|
127
|
-
|
128
|
-
#
|
129
|
-
# Look for any file matching pattern.
|
130
|
-
#
|
131
|
-
def msg_find_match
|
132
|
-
result = !Dir.glob( value ).empty?
|
133
|
-
$engine.heap.it.set_to result
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An object that can post JSON to a URI.
|
5
|
-
#
|
6
|
-
require 'net/ssh'
|
7
|
-
|
8
|
-
module GlooLang
|
9
|
-
module Objs
|
10
|
-
class SshExec < GlooLang::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'ssh_exec'.freeze
|
13
|
-
KEYWORD_SHORT = 'ssh'.freeze
|
14
|
-
HOST = 'host'.freeze
|
15
|
-
DEFAULT_HOST = 'localhost'.freeze
|
16
|
-
CMD = 'cmd'.freeze
|
17
|
-
RESULT = 'result'.freeze
|
18
|
-
HOST_REQUIRED_ERR = 'The host is required!'.freeze
|
19
|
-
|
20
|
-
#
|
21
|
-
# The name of the object type.
|
22
|
-
#
|
23
|
-
def self.typename
|
24
|
-
return KEYWORD
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
# The short name of the object type.
|
29
|
-
#
|
30
|
-
def self.short_typename
|
31
|
-
return KEYWORD_SHORT
|
32
|
-
end
|
33
|
-
|
34
|
-
# ---------------------------------------------------------------------
|
35
|
-
# Children
|
36
|
-
# ---------------------------------------------------------------------
|
37
|
-
|
38
|
-
#
|
39
|
-
# Does this object have children to add when an object
|
40
|
-
# is created in interactive mode?
|
41
|
-
# This does not apply during obj load, etc.
|
42
|
-
#
|
43
|
-
def add_children_on_create?
|
44
|
-
return true
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Add children to this object.
|
49
|
-
# This is used by containers to add children needed
|
50
|
-
# for default configurations.
|
51
|
-
#
|
52
|
-
def add_default_children
|
53
|
-
fac = $engine.factory
|
54
|
-
fac.create_string HOST, DEFAULT_HOST, self
|
55
|
-
fac.create_string CMD, nil, self
|
56
|
-
fac.create_string RESULT, nil, self
|
57
|
-
end
|
58
|
-
|
59
|
-
# ---------------------------------------------------------------------
|
60
|
-
# Messages
|
61
|
-
# ---------------------------------------------------------------------
|
62
|
-
|
63
|
-
#
|
64
|
-
# Get a list of message names that this object receives.
|
65
|
-
#
|
66
|
-
def self.messages
|
67
|
-
return super + [ 'run' ]
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# SSH to the host and execute the command, then update result.
|
72
|
-
#
|
73
|
-
def msg_run
|
74
|
-
h = host_value
|
75
|
-
unless h
|
76
|
-
$engine.err HOST_REQUIRED_ERR
|
77
|
-
return
|
78
|
-
end
|
79
|
-
|
80
|
-
Net::SSH.start( h ) do |ssh|
|
81
|
-
result = ssh.exec!( cmd_value )
|
82
|
-
update_result result
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# ---------------------------------------------------------------------
|
87
|
-
# Private functions
|
88
|
-
# ---------------------------------------------------------------------
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
#
|
93
|
-
# Get the host from the child object.
|
94
|
-
# Returns nil if there is none.
|
95
|
-
#
|
96
|
-
def host_value
|
97
|
-
o = find_child HOST
|
98
|
-
return nil unless o
|
99
|
-
|
100
|
-
return o.value
|
101
|
-
end
|
102
|
-
|
103
|
-
#
|
104
|
-
# Get the command from the child object.
|
105
|
-
# Returns nil if there is none.
|
106
|
-
#
|
107
|
-
def cmd_value
|
108
|
-
o = find_child CMD
|
109
|
-
return nil unless o
|
110
|
-
|
111
|
-
return o.value
|
112
|
-
end
|
113
|
-
|
114
|
-
#
|
115
|
-
# Set the result of the API call.
|
116
|
-
#
|
117
|
-
def update_result( data )
|
118
|
-
r = find_child RESULT
|
119
|
-
return nil unless r
|
120
|
-
|
121
|
-
r.set_value data
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|