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
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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/unparser/cli.rb', line 40 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
28 29 30 |
# File 'lib/unparser/cli.rb', line 28 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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/unparser/cli.rb', line 64 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
90 91 92 93 94 95 96 97 98 |
# File 'lib/unparser/cli.rb', line 90 def exit_status effective_sources.each do |source| next if @ignore.include?(source) process_source(source) break unless @success if @fail_fast end @success ? EXIT_SUCCESS : EXIT_FAILURE end |