Class: DevSystem::SimpleCommand
- Inherits:
-
BaseCommand
- Object
- Liza::Unit
- Liza::Controller
- Command
- BaseCommand
- DevSystem::SimpleCommand
- Defined in:
- lib/dev_system/subsystems/command/commands/simple_command.rb
Direct Known Subclasses
ArtSystem::ChatgptCommand, ArtSystem::DeepseekCommand, ArtSystem::OllamaCommand, ColorCommand, DeskSystem::GlimmerCommand, BenchCommand, GenerateCommand, IrbCommand, LogCommand, NewCommand, NotFoundCommand, PryCommand, ShellCommand, TestCommand, HappySystem::AxoCommand, LabSystem::DockerCommand, NetSystem::ClientCommand, NetSystem::DatabaseCommand, NetSystem::FilebaseCommand, NetSystem::RecordCommand, NetSystem::SocketCommand, PrimeSystem::EpicCommand, WebSystem::RackCommand, WebSystem::RequestCommand
Instance Attribute Summary
Attributes inherited from Liza::Controller
Instance Method Summary collapse
- #after ⇒ Object
- #ask? ⇒ Boolean
- #before ⇒ Object
- #default_args ⇒ Object
- #default_booleans ⇒ Object
- #default_strings ⇒ Object
- #given_args ⇒ Object
- #given_booleans ⇒ Object
- #given_strings ⇒ Object
- #input_args ⇒ Object
- #input_booleans ⇒ Object
- #input_strings ⇒ Object
-
#set_arg(index, name, default, title) ⇒ Object
Sets a default and input method for an argument.
-
#set_boolean(name, default, title) ⇒ Object
Sets a default and input method for a boolean.
- #set_default_arg(index, value) ⇒ Object
- #set_default_array(key, value) ⇒ Object
- #set_default_boolean(key, value) ⇒ Object
- #set_default_string(key, value) ⇒ Object
- #set_input_arg(index, &block) ⇒ Object
- #set_input_array(key, &block) ⇒ Object
- #set_input_boolean(key, &block) ⇒ Object
- #set_input_string(key, &block) ⇒ Object
-
#set_string(name, default, title) ⇒ Object
Sets a default and input method for a string parameter.
-
#simple_arg(index) ⇒ String
Retrieves a simple argument by index if given, then default, then input.
-
#simple_arg_ask(index, title) ⇒ String
Prompts the user to input a value for a specific argument by index.
-
#simple_arg_ask_snakecase(index, title, regexp: /^[a-zA-Z_]*$/) ⇒ String
May prompt the user to input a value for a specific argument by index, enforcing snake_case validation.
-
#simple_args ⇒ Array<String>
Retrieves all simple arguments.
-
#simple_args_from_2 ⇒ Array<String>
Retrieves all simple arguments from the second index onward.
-
#simple_array(key) ⇒ Array<String>
Retrieves an array of strings if given, then default, then input.
-
#simple_boolean(key) ⇒ Boolean
Retrieves a boolean if given, then default, then input.
-
#simple_boolean_yes(key, title) ⇒ Boolean
May prompt the user (default true) unless arg +key or -key is found.
-
#simple_booleans ⇒ Hash<Symbol, Boolean>
Retrieves all simple boolean arguments.
-
#simple_color(key, string: "I LOVE RUBY") ⇒ Symbol
Retrieves the value of an arg key=value.
-
#simple_controller_placement(key, places) ⇒ Object
key=value.
-
#simple_string(key) ⇒ String
Retrieves a string if given, then default, then input.
-
#simple_strings ⇒ Hash<Symbol, String>
Retrieves all simple string arguments.
Methods inherited from BaseCommand
#action_method_name, #action_name, #around, #call, call, #env, get_command_signatures, #not_found, typo, #typo
Methods inherited from Command
Methods inherited from Liza::Controller
#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token
Methods inherited from Liza::Unit
_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff
Instance Method Details
#after ⇒ Object
11 12 13 14 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 11 def after super after_simple end |
#ask? ⇒ Boolean
43 44 45 46 47 48 49 50 51 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 43 def ask? return @ask if defined? @ask ask = default_booleans[:ask] ask_arg = given_booleans[:ask] ask = ask_arg unless ask_arg.nil? @ask = ask end |
#before ⇒ Object
5 6 7 8 9 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 5 def before super before_given before_simple end |
#default_args ⇒ Object
53 54 55 56 57 58 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 53 def default_args h = get :default_args return h if h set :default_args, [] end |
#default_booleans ⇒ Object
82 83 84 85 86 87 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 82 def default_booleans h = get :default_booleans return h if h set :default_booleans, {} end |
#default_strings ⇒ Object
65 66 67 68 69 70 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 65 def default_strings h = get :default_strings return h if h set :default_strings, {} end |
#given_args ⇒ Object
18 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 18 def given_args = env[:given_args] |
#given_booleans ⇒ Object
22 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 22 def given_booleans = env[:given_booleans] |
#given_strings ⇒ Object
20 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 20 def given_strings = env[:given_strings] |
#input_args ⇒ Object
96 97 98 99 100 101 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 96 def input_args h = get :input_args return h if h set :input_args, [] end |
#input_booleans ⇒ Object
110 111 112 113 114 115 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 110 def input_booleans h = get :input_booleans return h if h set :input_booleans, {} end |
#input_strings ⇒ Object
103 104 105 106 107 108 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 103 def input_strings h = get :input_strings return h if h set :input_strings, {} end |
#set_arg(index, name, default, title) ⇒ Object
Sets a default and input method for an argument.
398 399 400 401 402 403 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 398 def set_arg(index, name, default, title) set_default_arg index, name, title set_input_arg index, name do |default| InputShell.ask title, default: default end end |
#set_boolean(name, default, title) ⇒ Object
Sets a default and input method for a boolean.
412 413 414 415 416 417 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 412 def set_boolean(name, default, title) set_default_boolean name, default set_input_boolean name do |default| InputShell.yes? title, default: default end end |
#set_default_arg(index, value) ⇒ Object
60 61 62 63 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 60 def set_default_arg(index, value) log :highest, "set_default_arg #{index.inspect} #{value.inspect}" default_args[index] = value end |
#set_default_array(key, value) ⇒ Object
77 78 79 80 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 77 def set_default_array(key, value) log :highest, "set_default_array #{key.inspect} #{value.inspect}" set_default_string key, value.join(",") end |
#set_default_boolean(key, value) ⇒ Object
89 90 91 92 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 89 def set_default_boolean(key, value) log :highest, "set_default_boolean #{key.inspect} #{value.inspect}" default_booleans[key] = value end |
#set_default_string(key, value) ⇒ Object
72 73 74 75 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 72 def set_default_string(key, value) log :highest, "set_default_string #{key.inspect} #{value.inspect}" default_strings[key] = value end |
#set_input_arg(index, &block) ⇒ Object
117 118 119 120 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 117 def set_input_arg(index, &block) log :highest, "set_input_arg #{index.inspect} #{block.source_location}" input_args[index] = block end |
#set_input_array(key, &block) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 127 def set_input_array(key, &block) log :highest, "set_input_array #{key.inspect}" set_input_string key do |default| block.call(default.to_s.split ",").join "," end end |
#set_input_boolean(key, &block) ⇒ Object
134 135 136 137 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 134 def set_input_boolean(key, &block) log :highest, "set_input_boolean #{key.inspect}" input_booleans[key] = block end |
#set_input_string(key, &block) ⇒ Object
122 123 124 125 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 122 def set_input_string(key, &block) log :highest, "set_input_string #{key.inspect}" input_strings[key] = block end |
#set_string(name, default, title) ⇒ Object
Sets a default and input method for a string parameter.
426 427 428 429 430 431 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 426 def set_string(name, default, title) set_default_string name, default set_input_string name do |default| InputShell.ask title, default: default end end |
#simple_arg(index) ⇒ String
Retrieves a simple argument by index if given, then default, then input.
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 145 def simple_arg(index) arg_given = given_args[index] arg_default = default_args[index] arg_input = input_args[index] arg = arg_given || arg_default arg = _arg_input_call(index) if arg_input and (ask? or arg.nil?) env[:simple_args][index] = arg arg end |
#simple_arg_ask(index, title) ⇒ String
Prompts the user to input a value for a specific argument by index.
351 352 353 354 355 356 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 351 def simple_arg_ask(index, title) set_input_arg index do |default| InputShell.ask(title, default: default) end simple_arg index end |
#simple_arg_ask_snakecase(index, title, regexp: /^[a-zA-Z_]*$/) ⇒ String
May prompt the user to input a value for a specific argument by index, enforcing snake_case validation.
364 365 366 367 368 369 370 371 372 373 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 364 def simple_arg_ask_snakecase(index, title, regexp: /^[a-zA-Z_]*$/) set_input_arg index do |default| InputShell.ask(title, default: default) do |q| q.required true q.validate regexp end.snakecase end simple_arg index end |
#simple_args ⇒ Array<String>
Retrieves all simple arguments.
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 203 def simple_args array = [] [ default_args, given_args, env[:simple_args] ].each do |args| args.each_with_index do |arg, i| array[i] = arg unless arg.nil? end end array end |
#simple_args_from_2 ⇒ Array<String>
Retrieves all simple arguments from the second index onward.
220 221 222 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 220 def simple_args_from_2 Array simple_args[2..-1] end |
#simple_array(key) ⇒ Array<String>
Retrieves an array of strings if given, then default, then input.
196 197 198 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 196 def simple_array(key) simple_string(key).to_s.split "," end |
#simple_boolean(key) ⇒ Boolean
Retrieves a boolean if given, then default, then input.
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 162 def simple_boolean(key) boolean_given = given_booleans[key] boolean_default = default_booleans[key] boolean_input = input_booleans[key] boolean = boolean_given.nil? ? boolean_default : boolean_given boolean = _boolean_input_call key if boolean_input and (ask? or boolean.nil?) env[:simple_booleans][key] = boolean boolean end |
#simple_boolean_yes(key, title) ⇒ Boolean
May prompt the user (default true) unless arg +key or -key is found.
380 381 382 383 384 385 386 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 380 def simple_boolean_yes(key, title) set_input_boolean key do |default| InputShell.yes? title, default: !!default end simple_boolean key end |
#simple_booleans ⇒ Hash<Symbol, Boolean>
Retrieves all simple boolean arguments.
227 228 229 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 227 def simple_booleans given_booleans.merge(default_booleans).merge(env[:simple_booleans]) end |
#simple_color(key, string: "I LOVE RUBY") ⇒ Symbol
Retrieves the value of an arg key=value. If a block is given and the key is not present, a color picker will be called to select a color.
318 319 320 321 322 323 324 325 326 327 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 318 def simple_color(key, string: "I LOVE RUBY") set_input_string key do |_default| InputShell.pick_color string: string end value = simple_string key value.to_sym.tap do |color| log :low, color.inspect end end |
#simple_controller_placement(key, places) ⇒ Object
key=value
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 330 def simple_controller_placement(key, places) set_input_string key do |_default| = places.map do |place, path| [ "#{place.ljust 30} path: #{path}", place ] end.to_h InputShell.pick_one "Where should the controller be placed?", end value = simple_string key value.tap do |place| log :low, place.inspect end end |
#simple_string(key) ⇒ String
Retrieves a string if given, then default, then input.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 179 def simple_string(key) string_given = given_strings[key] string_default = default_strings[key] string_input = input_strings[key] string = string_given || string_default string = _string_input_call key if string_input and (ask? or string.nil?) env[:simple_strings][key] = string string end |
#simple_strings ⇒ Hash<Symbol, String>
Retrieves all simple string arguments.
234 235 236 |
# File 'lib/dev_system/subsystems/command/commands/simple_command.rb', line 234 def simple_strings given_strings.merge(default_strings).merge(env[:simple_strings]) end |