Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/metasploit/framework/command/base.rb
Views: 11784
#1# Gems2#34require 'active_support/core_ext/module/introspection'56#7# Project8#910require 'metasploit/framework/command'11require 'metasploit/framework/parsed_options'12require 'metasploit/framework/require'1314# Based on pattern used for lib/rails/commands in the railties gem.15class Metasploit::Framework::Command::Base16#17# Attributes18#1920# @!attribute [r] application21# The Rails application for metasploit-framework.22#23# @return [Metasploit::Framework::Application]24attr_reader :application2526# @!attribute [r] parsed_options27# The parsed options from the command line.28#29# @return (see parsed_options)30attr_reader :parsed_options3132#33# Class Methods34#3536# @note {require_environment!} should be called to load37# `config/application.rb` to so that the RAILS_ENV can be set from the38# command line options in `ARGV` prior to `Rails.env` being set.39# @note After returning, `Rails.application` will be defined and configured.40#41# Parses `ARGV` for command line arguments to configure the42# `Rails.application`.43#44# @return (see parsed_options)45def self.require_environment!46parsed_options = self.parsed_options47# RAILS_ENV must be set before requiring 'config/application.rb'48parsed_options.environment!49ARGV.replace(parsed_options.positional)5051# allow other Rails::Applications to use this command52if !defined?(Rails) || Rails.application.nil?53# @see https://github.com/rails/rails/blob/v3.2.17/railties/lib/rails/commands.rb#L39-L4054require Pathname.new(__FILE__).parent.parent.parent.parent.parent.join('config', 'application')55end5657# have to configure before requiring environment because58# config/environment.rb calls initialize! and the initializers will use59# the configuration from the parsed options.60parsed_options.configure(Rails.application)6162Rails.application.require_environment!6364parsed_options65end6667def self.parsed_options68parsed_options_class.new69end7071def self.parsed_options_class72@parsed_options_class ||= parsed_options_class_name.constantize73end7475def self.parsed_options_class_name76@parsed_options_class_name ||= "#{module_parent.module_parent}::ParsedOptions::#{name.demodulize}"77end7879def self.start80parsed_options = require_environment!81new(application: Rails.application, parsed_options: parsed_options).start82end8384#85# Instance Methods86#8788# @param attributes [Hash{Symbol => ActiveSupport::OrderedOptions,Rails::Application}]89# @option attributes [Rails::Application] :application90# @option attributes [ActiveSupport::OrderedOptions] :parsed_options91# @raise [KeyError] if :application is not given92# @raise [KeyError] if :parsed_options is not given93def initialize(attributes={})94@application = attributes.fetch(:application)95@parsed_options = attributes.fetch(:parsed_options)96end9798# @abstract Use {#application} to start this command.99#100# Starts this command.101#102# @return [void]103# @raise [NotImplementedError]104def start105raise NotImplementedError106end107end108109110