Module: Skylab::Face::Command::TreeDefiner
- Included in:
- Skylab::Face::Cli, Namespace
- Defined in:
- lib/myterm/vendor/skylab/face/cli.rb
Instance Method Summary collapse
- #command_definitions ⇒ Object
- #command_tree ⇒ Object
-
#inherited(cls) ⇒ Object
this is nutty: for classes that extend this module, this is something that is triggered when they are subclasses.
- #method_added(name) ⇒ Object
-
#namespace(name, &block) ⇒ Object
You can rewrite the above in your class with another call to on() If you want to remove it, try: option_definitions.reject! { |a,_| ‘-h’ == a.first }.
- #on(*a, &b) ⇒ Object
- #option_definitions ⇒ Object
- #option_parser(*a, &b) ⇒ Object (also: #o)
Instance Method Details
#command_definitions ⇒ Object
172 173 174 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 172 def command_definitions @command_definitions ||= [] end |
#command_tree ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 144 def command_tree @command_tree ||= begin defined = command_definitions.map { |cls, a, b| cls.build(*a, &b) } defined_m = defined.map(&:method_symbol).compact implied_m = public_instance_methods(false).map(&:intern) - defined_m implied = implied_m.map { |m| Command.new(m) } Treeish[ defined + implied ] end end |
#inherited(cls) ⇒ Object
this is nutty: for classes that extend this module, this is something that is triggered when they are subclasses
155 156 157 158 159 160 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 155 def inherited cls cls.on('-h', '--help', 'show this screen') { help } # You can rewrite the above in your class with another call to on() # If you want to remove it, try: # option_definitions.reject! { |a,_| '-h' == a.first } end |
#method_added(name) ⇒ Object
175 176 177 178 179 180 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 175 def method_added name if @grab_next_method command_definitions.last[1][0] = name.to_sym @grab_next_method = false end end |
#namespace(name, &block) ⇒ Object
You can rewrite the above in your class with another call to on() If you want to remove it, try:
option_definitions.reject! { |a,_| '-h' == a.first }
161 162 163 164 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 161 def namespace name, &block def_block = name.kind_of?(Array) ? name : [Namespace, [name], block] command_definitions.push Namespace.add_definition(def_block) end |
#on(*a, &b) ⇒ Object
165 166 167 168 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 165 def on *a, &b block_given? or raise ArgumentError.new("block required") option_definitions.push [a, b] end |
#option_definitions ⇒ Object
169 170 171 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 169 def option_definitions @option_definitions ||= [] end |
#option_parser(*a, &b) ⇒ Object Also known as: o
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/myterm/vendor/skylab/face/cli.rb', line 181 def option_parser *a, &b block_given? or raise ArgumentError.new("block required") if a.empty? @grab_next_method and fail("can't have two anonymous " << "command definitions in a row.") @grab_next_method = true a = [nil] end command_definitions.push [Command, a, b] end |