Fix added for #78
Gracefully fail command line with unknown option https://github.com/beefproject/beef/issues/78 Now the framework suggests the user runs --help
This commit is contained in:
@@ -14,43 +14,49 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
module BeEF
|
||||
module Extension
|
||||
module Console
|
||||
#
|
||||
# This module parses the command line argument when running beef.
|
||||
#
|
||||
module CommandLine
|
||||
|
||||
@options = Hash.new
|
||||
@options[:verbose] = false
|
||||
@options[:resetdb] = false
|
||||
|
||||
@already_parsed = false
|
||||
|
||||
#
|
||||
# Parses the command line arguments of the console.
|
||||
# It also populates the 'options' hash.
|
||||
#
|
||||
def self.parse
|
||||
return @options if @already_parsed
|
||||
|
||||
optparse = OptionParser.new do |opts|
|
||||
opts.on('-x', '--reset', 'Reset the database') do
|
||||
@options[:resetdb] = true
|
||||
end
|
||||
|
||||
opts.on('-v', '--verbose', 'Display debug information') do
|
||||
@options[:verbose] = true
|
||||
module Extension
|
||||
module Console
|
||||
#
|
||||
# This module parses the command line argument when running beef.
|
||||
#
|
||||
module CommandLine
|
||||
|
||||
@options = Hash.new
|
||||
@options[:verbose] = false
|
||||
@options[:resetdb] = false
|
||||
|
||||
@already_parsed = false
|
||||
|
||||
#
|
||||
# Parses the command line arguments of the console.
|
||||
# It also populates the 'options' hash.
|
||||
#
|
||||
def self.parse
|
||||
return @options if @already_parsed
|
||||
|
||||
begin
|
||||
optparse = OptionParser.new do |opts|
|
||||
opts.on('-x', '--reset', 'Reset the database') do
|
||||
@options[:resetdb] = true
|
||||
end
|
||||
|
||||
opts.on('-v', '--verbose', 'Display debug information') do
|
||||
@options[:verbose] = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
optparse.parse!
|
||||
@already_parsed = true
|
||||
@options
|
||||
rescue OptionParser::InvalidOption => e
|
||||
puts "Invalid command line option provided. Please run beef --help"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
optparse.parse!
|
||||
@already_parsed = true
|
||||
@options
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user