Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-11686

Shell code should create a binding / irb workspace instead of polluting the root namespace

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.0-alpha-1, 2.4.0
    • shell
    • None
    • Incompatible change, Reviewed
    • Hide
      In shell, all HBase constants and commands have been moved out of the top-level and into an IRB Workspace. Piped stdin and scripts passed by name to the shell will be evaluated within this workspace. If you absolutely need the top-level definitions, use the new compatibility flag, ie. hbase shell --top-level-defs or hbase shell --top-level-defs script2run.rb.
      Show
      In shell, all HBase constants and commands have been moved out of the top-level and into an IRB Workspace. Piped stdin and scripts passed by name to the shell will be evaluated within this workspace. If you absolutely need the top-level definitions, use the new compatibility flag, ie. hbase shell --top-level-defs or hbase shell --top-level-defs script2run.rb.

    Description

      Right now, the shell builds a list of commands and then injects them into the root exectution's context

      bin/hirb.rb

      # Add commands to this namespace
      @shell.export_commands(self)
      

      hbase-shell/src/main/ruby/shell.rb

          def export_commands(where)
            ::Shell.commands.keys.each do |cmd|
              # here where is the IRB namespace
              # this method just adds the call to the specified command
              # which just references back to 'this' shell object
              # a decently extensible way to add commands
              where.send :instance_eval, <<-EOF
                def #{cmd}(*args)
                  ret = @shell.command('#{cmd}', *args)
                  puts
                  return ret
                end
              EOF
            end
          end
      

      This is an unclean abstraction. For one, it requires that there be an instance variable in the main namespace called '@shell' without making that clear in the docs. Additionally, it complicates maintenance by breaking isolation.

      We should update things so that shell can provide a binding for eval or a workspace for IRB execution and then use it directly when we construct our IRB session.

      Attachments

        Issue Links

          Activity

            People

              bitoffdev Elliot Miller
              busbey Sean Busbey
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: