Commit 69c0f291 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Turn Options::Processor into a facade.

So it hides all the internal options processing and we can use just
call this one static method in bin/jsduck.
parent da0d69dd
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -18,11 +18,9 @@
$:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"

require 'jsduck/app'
require 'jsduck/options/parser'
require 'jsduck/options/processor'

opts = JsDuck::Options::Parser.new.parse(ARGV)
JsDuck::Options::Processor.process!(opts)
opts = JsDuck::Options::Processor.process(ARGV)

exit_code = JsDuck::App.new(opts).run

+12 −7
Original line number Diff line number Diff line
require 'jsduck/options/parser'
require 'jsduck/options/input_files'
require 'jsduck/options/validator'
require 'jsduck/logger'
@@ -10,16 +11,20 @@ require 'jsduck/js/ext_patterns'
module JsDuck
  module Options

    # Handles setting different settings based on the commend line
    # options and also processes some of the options (like #input_files).
    # Finally it also validates them.
    # A facade for all the command line options processing.
    class Processor
      # Processes and applies the parsed command line options.
      # Also modifies the values of#input_files option.
      def self.process!(opts)
      # Takes a list of command line options, parses it to an
      # Options::Record object, validates the options, applies it to
      # various singleton classes and returns the Options::Record.
      def self.process(args)
        opts = Options::Parser.new.parse(args)

        # Expand list of input files
        Options::InputFiles.new(opts).expand!

        # Check for fatal problems (possibly exit the program).
        Options::Validator.new(opts).validate!

        # Configure various objects with these options
        Logger.configure(opts)
        Util::Parallel.configure(opts)
@@ -28,7 +33,7 @@ module JsDuck
        Util::Json.configure(opts)
        Util::IO.configure(opts)

        Options::Validator.new(opts).validate!
        opts
      end
    end