<commit_before>module Doxieland
  class Client
    attr_reader :save_path

    def initialize(options)
      @options       = options
      @save_path     = Pathname.new(options[:to] || '.').expand_path
    end

    def api(&block)
      Doxieland::Api.url "http://#{scanner_ip}:8080"

      if @options[:password]
        Doxieland::Api.http_basic_auth '<PASSWORD>', @options[:password]
      end

      api = Doxieland::Api.new

      begin
        yield api
      rescue AuthenticationError => e
        puts e.message
        exit
      end
    end

    def create_save_path
      raise ArgumentError, "#{@save_path} is a file" if @save_path.file?

      unless @save_path.directory? || @save_path == Pathname.new('.')
        FileUtils.mkdir_p(@save_path)
      end
    end

    def scanner_ip
      @scanner_ip ||= begin
        if @options['scanner-ip']
          @options['scanner-ip']
        elsif @options[:ap]
          '192.168.1.100'
        else
          discovered_ip = ssdp_discover

          unless discovered_ip
            puts "… sorry, your scanner could not be found. Is WiFi turned on and the status light blue?"
            puts "If you know it, you can also provide the IP address manually via the --scanner-ip flag."
            exit
          end<commit_msg>return a proper exit status on authentication errors<commit_after>module Doxieland
  class Client
    attr_reader :save_path

    def initialize(options)
      @options       = options
      @save_path     = Pathname.new(options[:to] || '.').expand_path
    end

    def api(&block)
      Doxieland::Api.url "http://#{scanner_ip}:8080"

      if @options[:password]
        Doxieland::Api.http_basic_auth '<PASSWORD>', @options[:password]
      end

      api = Doxieland::Api.new

      begin
        yield api
      rescue AuthenticationError => e
        puts e.message
        exit(false)
      end
    end

    def create_save_path
      raise ArgumentError, "#{@save_path} is a file" if @save_path.file?

      unless @save_path.directory? || @save_path == Pathname.new('.')
        FileUtils.mkdir_p(@save_path)
      end
    end

    def scanner_ip
      @scanner_ip ||= begin
        if @options['scanner-ip']
          @options['scanner-ip']
        elsif @options[:ap]
          '192.168.1.100'
        else
          discovered_ip = ssdp_discover

          unless discovered_ip
            puts "… sorry, your scanner could not be found. Is WiFi turned on and the status light blue?"
            puts "If you know it, you can also provide the IP address manually via the --scanner-ip flag."
            exit
          end
{'fraction_non_alphanumeric': 0.09763539282990084, 'fraction_numerical': 0.010678871090770405, 'mean_word_length': 2.100472813238771, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1515370', 'n_tokens_mistral': 813, 'n_tokens_neox': 784, 'n_words': 218}