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 <apurtell@apache.org>
This commit is contained in:
parent
d281ffb139
commit
f69a1945c6
|
@ -29,7 +29,7 @@ module Shell
|
||||||
@@command_groups
|
@@command_groups
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load_command(name, group)
|
def self.load_command(name, group, aliases=[])
|
||||||
return if commands[name]
|
return if commands[name]
|
||||||
|
|
||||||
# Register command in the group
|
# Register command in the group
|
||||||
|
@ -41,6 +41,9 @@ module Shell
|
||||||
require "shell/commands/#{name}"
|
require "shell/commands/#{name}"
|
||||||
klass_name = name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } # camelize
|
klass_name = name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } # camelize
|
||||||
commands[name] = eval("Commands::#{klass_name}")
|
commands[name] = eval("Commands::#{klass_name}")
|
||||||
|
aliases.each do |an_alias|
|
||||||
|
commands[an_alias] = commands[name]
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
raise "Can't load hbase shell command: #{name}. Error: #{e}\n#{e.backtrace.join("\n")}"
|
raise "Can't load hbase shell command: #{name}. Error: #{e}\n#{e.backtrace.join("\n")}"
|
||||||
end
|
end
|
||||||
|
@ -56,8 +59,11 @@ module Shell
|
||||||
:comment => opts[:comment]
|
:comment => opts[:comment]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
all_aliases = opts[:aliases] || {}
|
||||||
|
|
||||||
opts[:commands].each do |command|
|
opts[:commands].each do |command|
|
||||||
load_command(command, group)
|
aliases = all_aliases[command] || []
|
||||||
|
load_command(command, group, aliases)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -257,7 +263,10 @@ Shell.load_command_group(
|
||||||
alter_status
|
alter_status
|
||||||
alter_async
|
alter_async
|
||||||
get_table
|
get_table
|
||||||
]
|
],
|
||||||
|
:aliases => {
|
||||||
|
'describe' => ['desc']
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
Shell.load_command_group(
|
Shell.load_command_group(
|
||||||
|
|
|
@ -25,6 +25,10 @@ module Shell
|
||||||
Describe the named table. For example:
|
Describe the named table. For example:
|
||||||
hbase> describe 't1'
|
hbase> describe 't1'
|
||||||
hbase> describe 'ns1:t1'
|
hbase> describe 'ns1:t1'
|
||||||
|
|
||||||
|
Alternatively, you can use the abbreviated 'desc' for the same thing.
|
||||||
|
hbase> desc 't1'
|
||||||
|
hbase> desc 'nds1:t1'
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue