Class: Unparser::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/unparser/cli.rb,
lib/unparser/cli/differ.rb,
lib/unparser/cli/source.rb

Overview

Unparser CLI implementation

:reek:InstanceVariableAssumption :reek:TooManyInstanceVariables

Defined Under Namespace

Classes: Differ, Source

Constant Summary collapse

EXIT_SUCCESS =
0
EXIT_FAILURE =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize object

ignore :reek:TooManyStatements

Parameters:

  • arguments (Array<String>)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/unparser/cli.rb', line 44

def initialize(arguments)
  @sources = []
  @ignore = Set.new

  @success   = true
  @fail_fast = false
  @verbose   = false

  opts = OptionParser.new do |builder|
    add_options(builder)
  end

  opts.parse!(arguments).each do |name|
    @sources.concat(sources(name))
  end
end

Class Method Details

.run(*arguments) ⇒ Fixnum

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run CLI

Parameters:

  • arguments (Array<String>)

Returns:

  • (Fixnum)

    the exit status



31
32
33
# File 'lib/unparser/cli.rb', line 31

def self.run(*arguments)
  new(*arguments).exit_status
end

Instance Method Details

#add_options(builder) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add options

ignore :reek:TooManyStatements

Parameters:

  • builder (OptionParser)

Returns:

  • (undefined)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/unparser/cli.rb', line 70

def add_options(builder)
  builder.banner = 'usage: unparse [options] FILE [FILE]'
  builder.separator('')
  builder.on('-e', '--evaluate SOURCE') do |source|
    @sources << Source::String.new(source)
  end
  builder.on('--start-with FILE') do |file|
    @start_with = sources(file).first
  end
  builder.on('-v', '--verbose') do
    @verbose = true
  end
  builder.on('--ignore FILE') do |file|
    @ignore.merge(sources(file))
  end
  builder.on('--fail-fast') do
    @fail_fast = true
  end
end

#exit_statusFixnum

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return exit status

Returns:

  • (Fixnum)


96
97
98
99
100
101
102
103
104
105
# File 'lib/unparser/cli.rb', line 96

def exit_status
  effective_sources.each do |source|
    next if @ignore.include?(source)

    process_source(source)
    break if @fail_fast && !@success
  end

  @success ? EXIT_SUCCESS : EXIT_FAILURE
end