lib/snmp/open/command_reader.rb in snmp-open-0.1.5 vs lib/snmp/open/command_reader.rb in snmp-open-0.2.0
- old
+ new
@@ -39,17 +39,22 @@
#
# SNMP::Open.new(host: hostname, timeout: 3, '-m' => miblist)
# SNMP::Open.new(hostname => nil, '-t' => '3', '-m' => miblist)
#
def initialize(options)
+ @env = options.delete(:env)
host = options.delete(:host) ||
(raise ArgumentError, 'Host expected but not given')
opts = merge_options(options).merge('-On' => nil, host => nil)
@command_options, @host_options = partition_options(opts)
end
def capture(cmd, oid, options = {})
- out, err = Open3.capture3(cli(cmd, oid, options))
+ out, err = if @env
+ Open3.capture3(@env, cli(cmd, oid, options))
+ else
+ Open3.capture3(cli(cmd, oid, options))
+ end
raise CommandError, err.chomp unless err.empty?
out
end
# Generate a CLI command string