diff options
author | 0xAB <0xAB@protonmail.com> | 2017-08-27 11:37:51 +0100 |
---|---|---|
committer | 0xAB <0xAB@protonmail.com> | 2017-08-27 11:37:51 +0100 |
commit | c21d036cfd7fbb635338db55cbb97ac6f6038257 (patch) | |
tree | 78a2a2afb36c8774774eb370b41f03edcea8a85a | |
parent | 5053b5a6d09635b9621c25407f1fc7b141504ad0 (diff) | |
download | pry-c21d036cfd7fbb635338db55cbb97ac6f6038257.tar.gz |
add alias-prompt command
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/pry/commands/alias_prompt.rb | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 332b6118..06a87687 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### HEAD +* Add 'alias-prompt' command. * Add `Pry::Prompt.add_prompt()`, `Pry::Prompt.get_prompt()`, `Pry::Prompt.alias_prompt` and `Pry::Prompt.remove_prompt()`, for integrating custom prompts with Pry ([#1628](https://github.com/pry/pry/pull/1628)) diff --git a/lib/pry/commands/alias_prompt.rb b/lib/pry/commands/alias_prompt.rb new file mode 100644 index 00000000..1d592f8f --- /dev/null +++ b/lib/pry/commands/alias_prompt.rb @@ -0,0 +1,33 @@ +class Pry + class Command::AliasPrompt < Pry::ClassCommand + match "alias-prompt" + group 'Input and Output' + description "Create an alternative alias for a prompt" + banner <<-BANNER + alias-prompt PROMPT_NAME ALIAS_PROMPT + + Create an alternative alias for a prompt that can be seen from list-prompts and + used by the change-prompt commands. + BANNER + + command_options argument_required: true + + def process(prompt_name, alias_name) + if not args_ok?([prompt_name, alias_name]) + return output.puts help + end + if prompt = Pry::Prompt.get_prompt(prompt_name) + Pry::Prompt.alias_prompt prompt_name, alias_name + output.puts "Alias '#{alias_name}' created" + else + raise Pry::CommandError, "prompt #{prompt_name} cannot be aliased because it doesn't exist." + end + end + + private + def args_ok?(args) + args.size == 2 and args.all?{|s| String === s} + end + Pry::Commands.add_command(self) + end +end |