Module: EverydayThorUtil::SubCommandCommandHelpers
- Included in:
- SubCommandHelpers
- Defined in:
- lib/everyday_thor_util/plugin-helper.rb
Instance Method Summary collapse
- #create_cmd_class_and_aliases(aliases, command_array_symbol, command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc) ⇒ Object
- #create_cmd_method_and_aliases(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &block) ⇒ Object
- #create_command_class(command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc) ⇒ Object
- #extract_command_info(v) ⇒ Object
- #handle_command(command_array_symbol, command_symbol, flag_symbol, helper_symbol, parent_class, list, v) ⇒ Object
- #handle_command_class(command_array_symbol, command_symbol, flag_symbol, helper_symbol, list, parent_class, aliases, desc, id, long_desc, name, short_desc) ⇒ Object
- #handle_command_method(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &block) ⇒ Object
- #setup_command(desc, flag_symbol, id, long_desc, parent_class, short_desc) ⇒ Object
- #setup_root(flag_symbol, helper_symbol, parent, parent_class) ⇒ Object
Instance Method Details
#create_cmd_class_and_aliases(aliases, command_array_symbol, command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 79 def create_cmd_class_and_aliases(aliases, command_array_symbol, command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc) command_ids = Plugins.get_var command_array_symbol unless command_ids.include?(id) command_ids << id Plugins.set_var command_array_symbol, command_ids create_command_class(command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc) aliases.each { |a| create_command_class(command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, a, parent_class, short_desc.gsub(/^\S+(?=\s|$)/, a.gsub(/_/, '-'))) } if aliases end true end |
#create_cmd_method_and_aliases(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &block) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 90 def create_cmd_method_and_aliases(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &block) setup_command(desc, flag_symbol, id, long_desc, parent_class, short_desc) parent_class.create_method(name.to_sym, &block) aliases.each { |a| setup_command(desc, flag_symbol, id, long_desc, parent_class, short_desc.gsub(/^\S+(?=\s|$)/, a.gsub(/_/, '-'))) parent_class.dup_method a.to_sym, name.to_sym } if aliases true end |
#create_command_class(command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 109 def create_command_class(command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc) command_class = Class.new(Thor) command_class.namespace name Plugins.get helper_symbol, command_class, id unless helper_symbol.nil? Plugins.get flag_symbol, command_class, id, true Plugins.get command_symbol, command_class, id setup_command(desc, flag_symbol, id, long_desc, parent_class, short_desc) parent_class.subcommand name, command_class end |
#extract_command_info(v) ⇒ Object
100 101 102 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 100 def extract_command_info(v) return v[:options][:aliases], v[:options][:desc], v[:options][:id], v[:options][:long_desc], v[:options][:name], v[:options][:short_desc] end |
#handle_command(command_array_symbol, command_symbol, flag_symbol, helper_symbol, parent_class, list, v) ⇒ Object
125 126 127 128 129 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 125 def handle_command(command_array_symbol, command_symbol, flag_symbol, helper_symbol, parent_class, list, v) aliases, desc, id, long_desc, name, short_desc = extract_command_info(v) id && name && (handle_command_class(command_array_symbol, command_symbol, flag_symbol, helper_symbol, list, parent_class, aliases, desc, id, long_desc, name, short_desc) || handle_command_method(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &v[:block])) end |
#handle_command_class(command_array_symbol, command_symbol, flag_symbol, helper_symbol, list, parent_class, aliases, desc, id, long_desc, name, short_desc) ⇒ Object
131 132 133 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 131 def handle_command_class(command_array_symbol, command_symbol, flag_symbol, helper_symbol, list, parent_class, aliases, desc, id, long_desc, name, short_desc) (list.any? { |v2| v2[:options][:parent] == id } && create_cmd_class_and_aliases(aliases, command_array_symbol, command_symbol, desc, flag_symbol, helper_symbol, id, long_desc, name, parent_class, short_desc)) end |
#handle_command_method(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &block) ⇒ Object
135 136 137 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 135 def handle_command_method(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &block) (block && create_cmd_method_and_aliases(aliases, desc, flag_symbol, id, long_desc, name, parent_class, short_desc, &block)) end |
#setup_command(desc, flag_symbol, id, long_desc, parent_class, short_desc) ⇒ Object
119 120 121 122 123 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 119 def setup_command(desc, flag_symbol, id, long_desc, parent_class, short_desc) Plugins.get flag_symbol, parent_class, id, false parent_class.desc short_desc, desc if short_desc && desc parent_class.long_desc long_desc if long_desc end |
#setup_root(flag_symbol, helper_symbol, parent, parent_class) ⇒ Object
104 105 106 107 |
# File 'lib/everyday_thor_util/plugin-helper.rb', line 104 def setup_root(flag_symbol, helper_symbol, parent, parent_class) Plugins.get helper_symbol, parent_class, nil unless parent || helper_symbol.nil? Plugins.get flag_symbol, parent_class, nil, true unless parent end |