lib/ronin/ui/cli/cli.rb in ronin-1.0.0.rc3 vs lib/ronin/ui/cli/cli.rb in ronin-1.0.0

- old
+ new

@@ -19,10 +19,12 @@ require 'ronin/ui/cli/exceptions/unknown_command' require 'ronin/ui/cli/commands' require 'ronin/installation' +require 'set' + module Ronin module UI # # The {CLI} provides an extensible Command Line Interface (CLI) # for Ronin. The {CLI} can load any command using the {command} method, @@ -30,11 +32,12 @@ # module CLI # Name of the default to run DEFAULT_COMMAND = 'console' - @commands = {} + # The loaded command names + @commands = SortedSet[] # # All command-line names of Commands available to the {CLI}. # # @return [Hash] @@ -44,22 +47,19 @@ # def CLI.commands if @commands.empty? commands_dir = File.join('lib',Commands.namespace_root) - Installation.each_file(commands_dir) do |path| + Installation.each_file_in(commands_dir,:rb) do |path| # remove the .rb file extension name = path.chomp('.rb') # replace any file separators with a ':', to mimic the # naming convention of Rake/Thor. name.tr!(File::SEPARATOR,':') - - # replace all '_' and '-' characters with a single '_' character - name.gsub!(/[_-]+/,'_') - @commands[name] = path + @commands << name end end return @commands end @@ -88,13 +88,9 @@ # # @since 1.0.0 # def CLI.command(name) name = name.to_s - - # eventually someone is going to use a space or - which is going - # mess things up we will take care of this ahead of time here - name = name.gsub(/[\s_-]+/, '_') unless (command = Commands.require_const(name)) raise(UnknownCommand,"unable to load the command #{name.dump}",caller) end