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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.messagesObject

Get a list of message names that this object receives.



83
84
85
# File 'lib/shell.rb', line 83

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

.short_typenameObject

The short name of the object type.



25
26
27
# File 'lib/shell.rb', line 25

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



18
19
20
# File 'lib/shell.rb', line 18

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)


60
61
62
# File 'lib/shell.rb', line 60

def add_children_on_create?
  return true
end

#add_command(obj, command_data) ⇒ Object

Add a command to the shell.



116
117
118
119
# File 'lib/shell.rb', line 116

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.



69
70
71
72
73
# File 'lib/shell.rb', line 69

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.



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

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.



90
91
92
# File 'lib/shell.rb', line 90

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)


44
45
46
47
48
# File 'lib/shell.rb', line 44

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

#msg_startObject

Start the shell.



97
98
99
100
101
102
103
104
# File 'lib/shell.rb', line 97

def msg_start
  runner = get_runner

  # add_test_commands
  add_quit_command

  runner.start
end

#msg_stopObject

Stop the shell.



109
110
111
# File 'lib/shell.rb', line 109

def msg_stop
  @runner.stop if @runner
end

#promptObject

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



33
34
35
36
37
38
# File 'lib/shell.rb', line 33

def prompt
  o = find_child PROMPT
  return '' unless o

  return o.value
end

#set_context(key, value) ⇒ Object


Context



126
127
128
# File 'lib/shell.rb', line 126

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