Class: Command
- Inherits:
-
Gloo::Core::Obj
- Object
- Gloo::Core::Obj
- Command
- Defined in:
- lib/command.rb
Overview
- Author
-
Eric Crane (eric.crane@mac.com)
- Copyright
-
Copyright © 2026 Eric Crane. All rights reserved.
A CLI command.
Constant Summary collapse
- KEYWORD =
'command'.freeze
- KEYWORD_SHORT =
'command'.freeze
- DESCRIPTION =
'description'.freeze
- ACTION =
'action'.freeze
- DYNAMIC =
'dynamic'.freeze
- NODES =
'nodes'.freeze
- CONTEXT =
'context'.freeze
- OPTIONS =
'options'.freeze
- OPTIONS_KEY =
'options_key'.freeze
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#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.
-
#add_default_children ⇒ Object
Add children to this object.
- #context ⇒ Object
-
#description ⇒ Object
Get the description of the command.
-
#dynamic? ⇒ Boolean
Is this a dynamic command? It is dynamic if there is a dynamic child.
-
#dynamic_key ⇒ Object
Get the dynamic key for this command.
-
#get_child_nodes ⇒ Object
Get the child nodes for this command.
-
#get_command_data ⇒ Object
Get the command data for this command.
-
#msg_register ⇒ Object
Register the command with the shell.
-
#nodes ⇒ Object
Get the child nodes for this command.
-
#options ⇒ Object
Get the options for this command.
-
#options_key ⇒ Object
Get the options key for this command.
-
#run_action ⇒ Object
Run the action script.
- #run_action_with_context(context) ⇒ Object
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
152 153 154 |
# File 'lib/command.rb', line 152 def self. return super + [ 'register' ] end |
.short_typename ⇒ Object
The short name of the object type.
30 31 32 |
# File 'lib/command.rb', line 30 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
23 24 25 |
# File 'lib/command.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.
128 129 130 |
# File 'lib/command.rb', line 128 def add_children_on_create? return true end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
137 138 139 140 141 142 |
# File 'lib/command.rb', line 137 def add_default_children fac = @engine.factory fac.create_string NAME, '', self fac.create_string DESCRIPTION, '', self fac.create_script ACTION, '', self end |
#context ⇒ Object
63 64 65 66 |
# File 'lib/command.rb', line 63 def context o = find_child CONTEXT return o ? o : nil end |
#description ⇒ Object
Get the description of the command.
37 38 39 40 41 42 |
# File 'lib/command.rb', line 37 def description o = find_child DESCRIPTION return '' unless o return o.value end |
#dynamic? ⇒ Boolean
Is this a dynamic command? It is dynamic if there is a dynamic child. If so, it has contextual data.
49 50 51 52 53 |
# File 'lib/command.rb', line 49 def dynamic? o = find_child DYNAMIC return true if o return false end |
#dynamic_key ⇒ Object
Get the dynamic key for this command.
58 59 60 61 |
# File 'lib/command.rb', line 58 def dynamic_key o = find_child DYNAMIC return o ? o.value : nil end |
#get_child_nodes ⇒ Object
Get the child nodes for this command.
180 181 182 183 184 185 186 |
# File 'lib/command.rb', line 180 def get_child_nodes data = nodes.children.map do |child| child.get_command_data end return data end |
#get_command_data ⇒ Object
Get the command data for this command.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/command.rb', line 191 def get_command_data if dynamic? return { name: name, description: description, dynamic: true, obj: pn, method: "cmd_obj_action_with_context", source: dynamic_key } elsif nodes return { name: name, description: description, children: get_child_nodes } else return { name: name, description: description, method: "cmd_obj_action", obj: pn } end end |
#msg_register ⇒ Object
Register the command with the shell.
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/command.rb', line 159 def msg_register if @params&.token_count&.positive? pn = Gloo::Core::Pn.new( @engine, @params.first ) shell = pn.resolve shell.add_command( self, get_command_data ) # Are there options to add? if shell.set_context( , ) end end end |
#nodes ⇒ Object
Get the child nodes for this command.
93 94 95 96 |
# File 'lib/command.rb', line 93 def nodes o = find_child NODES return o ? o : nil end |
#options ⇒ Object
Get the options for this command.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/command.rb', line 79 def arr = [] o = find_child OPTIONS if o arr = o.children.map { |child| child.value } end return arr end |
#options_key ⇒ Object
Get the options key for this command.
71 72 73 74 |
# File 'lib/command.rb', line 71 def o = find_child OPTIONS_KEY return o ? o.value : nil end |
#run_action ⇒ Object
Run the action script.
101 102 103 104 105 106 |
# File 'lib/command.rb', line 101 def run_action o = find_child ACTION return unless o Gloo::Exec::Dispatch.( @engine, 'run', o ) end |