Class: Shell

Inherits:
Gloo::Core::Obj
  • Object
show all
Defined in:
lib/shell.rb

Overview

Author

Eric Crane (eric.crane@mac.com)

Copyright

Copyright © 2026 Eric Crane. All rights reserved.

A CLI shell.

Constant Summary collapse

KEYWORD =
'shell'.freeze
KEYWORD_SHORT =
'shell'.freeze
PROMPT =
'prompt'.freeze
DEFAULT_ACTION =
'default_action'.freeze
INCLUDE_QUIT =
'include_quit'.freeze
ON_ERROR =
'on_error'.freeze
ON_UNKNOWN_CMD =
'on_unknown_command'.freeze
ON_EMPTY_CMD =
'on_empty_command'.freeze
BEFORE_ACTION =
'before_action'.freeze
AFTER_ACTION =
'after_action'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.messagesObject

Get a list of message names that this object receives.



88
89
90
# File 'lib/shell.rb', line 88

def self.messages
  return super + [ 'start', 'stop' ]
end

.short_typenameObject

The short name of the object type.



30
31
32
# File 'lib/shell.rb', line 30

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



23
24
25
# File 'lib/shell.rb', line 23

def self.typename
  return KEYWORD
end

Instance Method Details

#add_children_on_create?Boolean

Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.

Returns:

  • (Boolean)


65
66
67
# File 'lib/shell.rb', line 65

def add_children_on_create?
  return true
end

#add_command(obj, command_data) ⇒ Object

Add a command to the shell.



121
122
123
124
# File 'lib/shell.rb', line 121

def add_command obj, command_data
  runner = get_runner
  runner.add_command_node( command_data )
end

#add_default_childrenObject

Add children to this object. This is used by containers to add children needed for default configurations.



74
75
76
77
78
# File 'lib/shell.rb', line 74

def add_default_children
  fac = @engine.factory
  fac.create_string PROMPT, '> ', self
  fac.create_script DEFAULT_ACTION, '', self
end

#add_quit_commandObject

Quit the shell.



199
200
201
202
203
204
205
206
207
# File 'lib/shell.rb', line 199

def add_quit_command
  return unless include_quit?
  
  @runner.add_command_node({
    name: "quit",
    description: "Quit the application", 
    method: "cmd_quit"
  })
end

#get_runnerObject

Get the shell runner or initialize it if it doesn’t exist.



95
96
97
# File 'lib/shell.rb', line 95

def get_runner
  return @runner ||= ShellRunner.new( @engine, self )
end

#include_quit?Boolean

Get the value of the include_quit child object. Returns false if there is none.

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/shell.rb', line 49

def include_quit?
  o = find_child INCLUDE_QUIT
  return o.value if o
  return false
end

#msg_startObject

Start the shell.



102
103
104
105
106
107
108
109
# File 'lib/shell.rb', line 102

def msg_start
  runner = get_runner

  # add_test_commands
  add_quit_command

  runner.start
end

#msg_stopObject

Stop the shell.



114
115
116
# File 'lib/shell.rb', line 114

def msg_stop
  @runner.stop if @runner
end

#promptObject

Get the value of the prompt child object. Returns nil if there is none.



38
39
40
41
42
43
# File 'lib/shell.rb', line 38

def prompt
  o = find_child PROMPT
  return '' unless o

  return o.value
end

#run_after_actionObject

Run the after_action script if one exists.



184
185
186
187
188
189
# File 'lib/shell.rb', line 184

def run_after_action
  o = find_child AFTER_ACTION
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#run_before_actionObject

Run the before_action script if one exists.



174
175
176
177
178
179
# File 'lib/shell.rb', line 174

def run_before_action
  o = find_child BEFORE_ACTION
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#run_on_empty_cmdObject

Run the on_empty_command script if one exists. Returns true if the script was found and run, false otherwise.



163
164
165
166
167
168
169
# File 'lib/shell.rb', line 163

def run_on_empty_cmd
  o = find_child ON_EMPTY_CMD
  return false unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
  return true
end

#run_on_errorObject

Run the on_error script if one exists. Returns true if the script was found and run, false otherwise.



139
140
141
142
143
144
145
# File 'lib/shell.rb', line 139

def run_on_error
  o = find_child ON_ERROR
  return false unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
  return true
end

#run_on_unknown_cmdObject

Run the on_unknown_cmd script if one exists. Returns true if the script was found and run, false otherwise.



151
152
153
154
155
156
157
# File 'lib/shell.rb', line 151

def run_on_unknown_cmd
  o = find_child ON_UNKNOWN_CMD
  return false unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
  return true
end

#set_context(key, value) ⇒ Object


Context



131
132
133
# File 'lib/shell.rb', line 131

def set_context key, value
  @runner.set_context( key, value )
end