Class: Unparser::CLI
- Inherits:
-
Object
- Object
- Unparser::CLI
- 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
Constant Summary collapse
- EXIT_SUCCESS =
0
- EXIT_FAILURE =
1
Class Method Summary collapse
-
.run(*arguments) ⇒ Fixnum
private
Run CLI.
Instance Method Summary collapse
-
#add_options(builder) ⇒ undefined
private
Add options.
-
#exit_status ⇒ Fixnum
private
Return exit status.
-
#initialize(arguments) ⇒ undefined
constructor
private
Initialize object.
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
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| (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
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
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 (builder) builder. = '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_status ⇒ 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.
Return exit status
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 |