Class: Tailor::CLI

Inherits:
Object
  • Object
show all
Includes:
LogSwitch::Mixin
Defined in:
lib/tailor/cli.rb,
lib/tailor/cli/options.rb

Overview

The Command-Line Interface worker. Execution from the command line comes through here.

Defined Under Namespace

Classes: Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • args (Array)

    Arguments from the command-line.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tailor/cli.rb', line 26

def initialize(args)
  options = Options.parse!(args)
  @configuration = Configuration.new(args, options)
  @configuration.load!

  if options.show_config
    @configuration.show
    exit
  end

  @critic = Critic.new
  @reporter = Reporter.new(@configuration.formatters)
end

Instance Attribute Details

#configurationTailor::Configuration (readonly)



16
17
18
# File 'lib/tailor/cli.rb', line 16

def configuration
  @configuration
end

Class Method Details

.run(args) ⇒ Object

The main method of execution from the command line.

Parameters:

  • args (Array)

    Arguments from the command-line.



21
22
23
# File 'lib/tailor/cli.rb', line 21

def self.run(args)
  new(args).execute!
end

Instance Method Details

#execute!Boolean

This checks all of the files detected during the configuration gathering process, then hands results over to the Reporter to be reported.

Returns:

  • (Boolean)

    true if no problems were detected; false if there were.



45
46
47
48
49
50
51
52
53
54
# File 'lib/tailor/cli.rb', line 45

def execute!
  @critic.critique(@configuration.file_sets) do |problems_for_file, label|
    @reporter.file_report(problems_for_file, label)
  end

  @reporter.summary_report(@critic.problems,
    output_file: @configuration.output_file)

  @critic.problem_count(:error) > 0
end

#resultHash{String => Array}

Critiques all file sets, then returns the problems found as a result.

Returns:

  • (Hash{String => Array})

    The list of problems, where the keys are the file names in which the problems were found, and the values are the respective lists of problems for each file.



61
62
63
64
# File 'lib/tailor/cli.rb', line 61

def result
  @critic.critique(@configuration.file_sets)
  @critic.problems
end