Module: Wpxf::Cli::Options
- Included in:
- Console
- Defined in:
- lib/wpxf/cli/options.rb
Overview
Methods for handling commands that interact with module options.
Instance Attribute Summary collapse
-
#global_opts ⇒ Object
Returns the value of attribute global_opts.
Instance Method Summary collapse
- #apply_global_options(target) ⇒ Object
- #gset(name, *args) ⇒ Object
- #gunset(name) ⇒ Object
- #initialize ⇒ Object
- #load_payload(name) ⇒ Object
- #set(name, *args) ⇒ Object
- #set_option_value(name, value, silent = false) ⇒ Object
- #unset(name) ⇒ Object
Instance Attribute Details
#global_opts ⇒ Object
Returns the value of attribute global_opts.
102 103 104 |
# File 'lib/wpxf/cli/options.rb', line 102 def global_opts @global_opts end |
Instance Method Details
#apply_global_options(target) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/wpxf/cli/options.rb', line 27 def (target) return if target.nil? global_opts.each do |k, v| target.set_option_value(k, v) end end |
#gset(name, *args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wpxf/cli/options.rb', line 67 def gset(name, *args) if name.eql? 'payload' print_warning 'The payload cannot be globally set' return end value = args.join(' ') global_opts[name] = value set_option_value(name, value, true) if context print_good "Globally set the value of #{name} to #{value}" end |
#gunset(name) ⇒ Object
80 81 82 83 84 |
# File 'lib/wpxf/cli/options.rb', line 80 def gunset(name) global_opts.delete(name) context.module.unset_option(name) if module_loaded? print_good "Removed the global setting for #{name}" end |
#initialize ⇒ Object
7 8 9 10 |
# File 'lib/wpxf/cli/options.rb', line 7 def initialize super self.global_opts = {} end |
#load_payload(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wpxf/cli/options.rb', line 34 def load_payload(name) if context.module.aux_module? print_warning 'Auxiliary modules do not use payloads' return end begin payload = context.load_payload(name) print_good "Loaded payload: #{payload}" rescue StandardError => e print_bad "Failed to load payload: #{e}" print_bad e.backtrace.join("\n\t") return end (payload) end |
#set(name, *args) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/wpxf/cli/options.rb', line 86 def set(name, *args) value = args.join(' ') return unless module_loaded? begin if name.eql? 'payload' load_payload(value) else set_option_value(name, value) end rescue StandardError => e print_bad "Failed to set #{name}: #{e}" print_bad e.backtrace.join("\n\t") end end |
#set_option_value(name, value, silent = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wpxf/cli/options.rb', line 53 def set_option_value(name, value, silent = false) res = context.module.set_option_value(name, value) return if silent if res == :not_found print_warning "\"#{name}\" is not a valid option" elsif res == :invalid print_bad "\"#{value}\" is not a valid value" else print_good "Set #{name} => #{res}" end end |
#unset(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wpxf/cli/options.rb', line 12 def unset(name) unless context print_bad 'No module loaded yet' return end if name.eql?('payload') context.module.payload = nil else context.module.unset_option(name) end print_good "Unset #{name}" end |