Sha256: 4d86b8c9a9f80c46446f9907581220c096e702731c1d63fb1f304fe7983ba993

Contents?: true

Size: 904 Bytes

Versions: 3

Compression:

Stored size: 904 Bytes

Contents

require_relative '../seeker'
require 'slop'
require 'net/netrc'

module Seeker
  class CLI
    NETRC_MACHINE = 'Seeker'
    attr_reader :result
    class NoAuthFound < SeekerError; end
    class MissingHost < SeekerError; end

    private
    def initialize
      @opts = opts_parse
      if not @opts.present? :debug
        Seeker.debug = 0
      elsif @opts[:debug]
        Seeker.debug = @opts[:debug].to_i
      else
        Seeker.debug = 1
      end
      Log.level = Logger::DEBUG if Seeker.debug > 0
      args = @opts.parse
      @host = args.first
      raise MissingHost, 'no host given as argument' unless @host
      @user, @password = netrc_get
      @result = seek
    end

    def netrc_get machine=NETRC_MACHINE
      auth = Net::Netrc.locate machine
      [auth.login, auth.password] rescue raise NoAuthFound, "could not find authentication for #{machine} in .netrc"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
seeker-junos-0.2.0 lib/seeker/cli.rb
seeker-junos-0.1.0 lib/seeker/cli.rb
seeker-junos-0.0.5 lib/seeker/cli.rb