<commit_before># encoding: utf-8

usage       'autocompile [options]'
summary     'start the autocompiler'
aliases     :aco
description <<-EOS
Start the autocompiler web server. Unless specified, the web server will run
on port 3000 and listen on all IP addresses. Running the autocompiler requires
the 'mime/types' and 'rack' gems.
EOS

required :H, :handler, 'specify the handler to use (webrick/mongrel/…)'
required :o, :host,    'specify the host to listen on (default: 0.0.0.0)'
required :p, :port,    'specify the port to listen on (default: 3000)'

module Nanoc::CLI::Commands

  class AutoCompile < ::Nanoc::CLI::CommandRunner

    def run
      require 'rack'

      # Make sure we are in a nanoc site directory
      self.require_site

      # Set options
      options_for_rack = {
        :Port      => (options[:port] || 3000).to_i,
        :Host      => (options[:host] || '0.0.0.0')
      }

      # Guess which handler we should use
      unless handler = Rack::Handler.get(options[:handler])
        begin
          handler = Rack::Handler::Mongrel
        rescue LoadError => e
          handler = Rack::Handler::WEBrick
        end
      end

      # Build app
      autocompiler = Nanoc::Extra::AutoCompiler.new('.')
      app = Rack::Builder.new do
        use Rack::CommonLogger, $stderr
        use Rack::ShowExceptions
        run autocompiler
      end.to_app

      # Run autocompiler
      puts "Running on http://#{options_for_rack[:Host]}:#{options_for_rack[:Port]}/"
      handler.run(app, options_for_rack)
    end

  end

end

runner Nanoc::CLI::Commands::AutoCompile<commit_msg>Adding ability to specify host and/or port options for the autocompile command in config.yaml<commit_after># encoding: utf-8

usage       'autocompile [options]'
summary     'start the autocompiler'
aliases     :aco
description <<-EOS
Start the autocompiler web server. Unless overridden with commandline options
or configuration entries, the web server will run on port 3000 and listen on all
IP addresses. Running the autocompiler requires the 'mime/types' and 'rack' gems.

To specify the host and/or port options in config.yaml, you can add the following:

  autocompile:
    host: '10.0.2.0'  # override the default host
    port: 4000        # override the default port

EOS

required :H, :handler, 'specify the handler to use (webrick/mongrel/…)'
required :o, :host,    'specify the host to listen on (default: 0.0.0.0)'
required :p, :port,    'specify the port to listen on (default: 3000)'

module Nanoc::CLI::Commands

  class AutoCompile < ::Nanoc::CLI::CommandRunner

    def run
      require 'rack'

      # Make sure we are in a nanoc site directory
      self.require_site
      autocompile_config = self.site.config[:autocompile] || {}

      # Set options
      options_for_rack = {
        :Port      => (options[:port] || autocompile_config[:port] || 3000).to_i,
        :Host      => (options[:host] || autocompile_config[:host] || '0.0.0.0')
      }

      # Guess which handler we should use
      unless handler = Rack::Handler.get(options[:handler])
        begin
          handler = Rack::Handler::Mongrel
        rescue LoadError => e
          handler = Rack::Handler::WEBrick
        end
      end

      # Build app
      autocompiler = Nanoc::Extra::AutoCompiler.new('.')
      app = Rack::Builder.new do
        use Rack::CommonLogger, $stderr
        use Rack::ShowExceptions
        run autocompiler
      end.to_app

      # Run autocompiler
      puts "Running on http://#{options_for_rack[:Host]}:#{options_for_rack[:Port]}/"
      handler.run(app, options_for_rack)
    end

  end

end

runner Nanoc::CLI::Commands::AutoCompile
{'fraction_non_alphanumeric': 0.10663764961915125, 'fraction_numerical': 0.013873775843307944, 'mean_word_length': 2.8623949579831933, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '509054', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1124, 'n_words': 351}