<commit_before>module IPVSLitmus
  module CLI
    class Admin
      def run(argv = ARGV)
        command = argv.shift
        send(command, argv)
      end

      def status(args)
        service = args.shift

        response = Net::HTTP.get_response(URI.parse("http://localhost:9292/#{service}/status"))
        puts response.body

        case response
        when Net::HTTPSuccess then exit 0
        when Net::HTTPClientError then exit 2
        else exit 1
        end
      end
    end
  end
end<commit_msg>litmusctl status options and handle connection error.<commit_after>module IPVSLitmus
  module CLI
    class Admin
      def run(argv = ARGV)
        command = argv.shift
        send(command, argv)
      end

      def status(args)
        options = { :port => 9292, :host => 'localhost' }
        opt_parser = OptionParser.new do |opts|
          opts.banner = "Usage: litmusctl status <service> [options]"
          opts.on("-p", "--port=port", Integer,
                  "Port litmus is running on", "Default: 9292") { |v| options[:port] = v }
          opts.on("-h", "--host=ip", String,
                  ":Host litmus is running on", "Default: localhost") { |v| options[:host] = v }

          opts.separator ""

          opts.on("--help", "Show this help message.") { puts opts; exit }
        end

        opt_parser.parse! args
        service = args.shift

        begin
          response = Net::HTTP.get_response(URI.parse("http://#{options[:host]}:#{options[:port]}/#{service}/status"))
          puts response.body
          case response
          when Net::HTTPSuccess then exit 0
          when Net::HTTPClientError then exit 2
          else exit 1
          end
        rescue Errno::ECONNREFUSED => e
          puts "Unable to connect to litmus on #{options[:host]}:#{options[:port]}: #{e.message}"
          exit 1
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11528291909042834, 'fraction_numerical': 0.010047593865679535, 'mean_word_length': 1.979527559055118, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '7433207', 'n_tokens_mistral': 557, 'n_tokens_neox': 538, 'n_words': 158}