From 08c14bd5025977a606fbe9b3e7e256a9c83a4b91 Mon Sep 17 00:00:00 2001 From: Sean Busbey Date: Thu, 21 Aug 2014 11:12:42 -0500 Subject: [PATCH] HBASE-8298 In shell, provide alias of 'desc' for 'describe'. * Adds ability to alias commands * map 'desc' alias to 'describe' Signed-off-by: Andrew Purtell --- hbase-shell/src/main/ruby/shell.rb | 15 ++++++++++++--- .../src/main/ruby/shell/commands/describe.rb | 4 ++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 230445c3f41..7e948b71bc3 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -29,7 +29,7 @@ module Shell @@command_groups end - def self.load_command(name, group) + def self.load_command(name, group, aliases=[]) return if commands[name] # Register command in the group @@ -41,6 +41,9 @@ module Shell require "shell/commands/#{name}" klass_name = name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } # camelize commands[name] = eval("Commands::#{klass_name}") + aliases.each do |an_alias| + commands[an_alias] = commands[name] + end rescue => e raise "Can't load hbase shell command: #{name}. Error: #{e}\n#{e.backtrace.join("\n")}" end @@ -56,8 +59,11 @@ module Shell :comment => opts[:comment] } + all_aliases = opts[:aliases] || {} + opts[:commands].each do |command| - load_command(command, group) + aliases = all_aliases[command] || [] + load_command(command, group, aliases) end end @@ -254,7 +260,10 @@ Shell.load_command_group( alter_status alter_async get_table - ] + ], + :aliases => { + 'describe' => ['desc'] + } ) Shell.load_command_group( diff --git a/hbase-shell/src/main/ruby/shell/commands/describe.rb b/hbase-shell/src/main/ruby/shell/commands/describe.rb index 9e2996fcc61..9e48491d813 100644 --- a/hbase-shell/src/main/ruby/shell/commands/describe.rb +++ b/hbase-shell/src/main/ruby/shell/commands/describe.rb @@ -25,6 +25,10 @@ module Shell Describe the named table. For example: hbase> describe 't1' hbase> describe 'ns1:t1' + +Alternatively, you can use the abbreviated 'desc' for the same thing. + hbase> desc 't1' + hbase> desc 'nds1:t1' EOF end