diff --git src/main/ruby/shell.rb src/main/ruby/shell.rb index 53f3de8..50cacfe 100644 --- src/main/ruby/shell.rb +++ src/main/ruby/shell.rb @@ -93,10 +93,13 @@ module Shell def export_commands(where) ::Shell.commands.keys.each do |cmd| + #define the command name in 'where' namespace + #which actually just delegates to the shell instance where.send :instance_eval, <<-EOF def #{cmd}(*args) - @shell.command('#{cmd}', *args) + ret = @shell.command('#{cmd}', *args) puts + return ret end EOF end @@ -211,6 +214,7 @@ Shell.load_command_group( :commands => %w[ status version + get_table ] ) diff --git src/main/ruby/shell/commands.rb src/main/ruby/shell/commands.rb index af6df33..0ec286e 100644 --- src/main/ruby/shell/commands.rb +++ src/main/ruby/shell/commands.rb @@ -28,7 +28,8 @@ module Shell end def command_safe(debug, *args) - translate_hbase_exceptions(*args) { command(*args) } + ret = translate_hbase_exceptions(*args) { command(*args) } + return ret rescue => e puts puts "ERROR: #{e}" @@ -37,8 +38,6 @@ module Shell puts "Here is some help for this command:" puts help puts - ensure - return nil end def admin @@ -69,6 +68,14 @@ module Shell formatter.header formatter.footer(now) end + + def format_and_return_simple_command + now = Time.now + ret = yield + formatter.header + formatter.footer(now) + return ret + end def translate_hbase_exceptions(*args) yield diff --git src/main/ruby/shell/commands/get_table.rb src/main/ruby/shell/commands/get_table.rb new file mode 100644 index 0000000..ceb8ead --- /dev/null +++ src/main/ruby/shell/commands/get_table.rb @@ -0,0 +1,48 @@ +# +# Copyright 2010 The Apache Software Foundation +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module Shell + module Commands + class GetTable < Command + def help + return <<-EOF +Get the given table name and return it as an actual object to +be manipulated by the user. See table.help for more information +on how to use the table. +Eg. + + hbase> t1 = get_table 't1' + +returns the table named 't1' as a table object. You can then do + + hbase> t1.help + +which will then print the table for that table. +EOF + end + + def command(table, *args) + format_and_return_simple_command do + table(table) + end + end + end + end +end diff --git src/test/ruby/hbase/admin_test.rb src/test/ruby/hbase/admin_test.rb index 0c2672b..278090b 100644 --- src/test/ruby/hbase/admin_test.rb +++ src/test/ruby/hbase/admin_test.rb @@ -310,5 +310,13 @@ module Hbase assert_no_match(eval("/" + key1 + "\\$(\\d+)/"), admin.describe(@test_name)) assert_no_match(eval("/" + key2 + "/"), admin.describe(@test_name)) end + + define_test "get_table should get a real table" do + drop_test_table(@test_name) + create_test_table(@test_name) + + table = table(@test_name) + assert_not_equal(nil, table) + end end end diff --git src/test/ruby/hbase/table_test.rb src/test/ruby/hbase/table_test.rb index 5d56e18..d455470 100644 --- src/test/ruby/hbase/table_test.rb +++ src/test/ruby/hbase/table_test.rb @@ -123,7 +123,7 @@ module Hbase define_test "put should work with integer values" do @test_table.put("123", "x:a", 4) end - + #------------------------------------------------------------------------------- define_test "delete should work without timestamp" do