We should not rely on default commands, because they can be removed or
shuffled around in the future. Use our custom command in the tests.
Also, add a test that ensures that a group does not disappear after the
call without parameters.
Reported-by: John Mair <jrmair@gmail.com>
Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
Fix issue #631 (In `help` output: aliases are no longer grouped under
Aliases heading but under (other))
Forbid redefining a group of a command once it is initialized. Also, add
some unit tests, checking for that, so we won't miss this if it happens
next time.
Reported-by: John Mair <jrmair@gmail.com>
Cc: Rob Gleeson <rob@flowof.info>
Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
Commands can store state on an `OpenStruct` exposed via the `state` method.
This `OpenStruct` is guaranteed to be unique to the command and to the associated Pry instance.
e.g
create_command "my-test" do
def process
state.my_state ||= 0
state.my_state += 1
end
end
The above `state.my_state` variable will increment by one for each invocation of `my-test`.
Further, it will not intefere with any state on `my-test` for any other Pry instance or with
any `state.my_state` variables defined for other commands on the same Pry instance.
When creating a command using a custom subclass there may not be a
readily available block. In that case defaulting to the process method
seems reasonable for now.
* blocks can no longer be passed explicitly into commands via command "blah", "desc" |&block| (1.8 compatibility problems)
* blocks must be explicitly enabled for a command with the :takes_block => true option
e.g:
command "hello", "desc" do |&block|
block.call
end
(pry)> hello | do
(pry)* puts "mommy, make me all silver!"
(pry)* end
mommy, make me all silver!
* Blocks are now available by default, turn off explicitly with :takes_block => false
* Example, using &block:
Pry.commands.command "tobina", "desc", :takes_block => true do |&block|
block.call
end
(pry)> tobina { puts "hi" }
hi
(pry)>
* Works with process(&block) too (for create_command)
* Works with do/end blocks and {} blocks, both single and multi-line
* Example, using command_block:
Pry.commands.command "tobina", "desc", :takes_block => true do
command_block.call
end
The CommandSet is responsible for storing Commands, while the Commands
themselves are responsible for all the parsing.
(Before this change, the CommandProcessor used to do both the searching
within the CommandSet's and also the tokenization of command arguments)