Class: Unparser::CLI
- Inherits:
-
Object
- Object
- Unparser::CLI
- Defined in:
- lib/unparser/cli.rb
Overview
Unparser CLI implementation
Defined Under Namespace
Classes: Target
Constant Summary collapse
- EXIT_SUCCESS =
0
- EXIT_FAILURE =
1
Class Method Summary collapse
-
.run(*arguments) ⇒ Integer
private
Run CLI.
Instance Method Summary collapse
-
#add_options(builder) ⇒ undefined
private
Add options.
-
#exit_status ⇒ Integer
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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/unparser/cli.rb', line 74 def initialize(arguments) @ignore = Set.new @targets = [] @fail_fast = false @start_with = nil @success = true @validation = :validation @verbose = false opts = OptionParser.new do |builder| (builder) end opts.parse!(arguments).each do |name| @targets.concat(targets(name)) end end |
Class Method Details
.run(*arguments) ⇒ Integer
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
63 64 65 |
# File 'lib/unparser/cli.rb', line 63 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
rubocop:disable Metrics/MethodLength
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/unparser/cli.rb', line 102 def (builder) builder. = 'usage: unparse [options] FILE [FILE]' builder.separator('') builder.on('-e', '--evaluate SOURCE') do |source| @targets << Target::String.new(source) end builder.on('--start-with FILE') do |path| @start_with = targets(path).first end builder.on('-v', '--verbose') do @verbose = true end builder.on('-l', '--literal') do @validation = :literal_validation end builder.on('--ignore FILE') do |file| @ignore.merge(targets(file)) end builder.on('--fail-fast') do @fail_fast = true end end |
#exit_status ⇒ Integer
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
132 133 134 135 136 137 138 139 |
# File 'lib/unparser/cli.rb', line 132 def exit_status effective_targets.each do |target| process_target(target) break if @fail_fast && !@success end @success ? EXIT_SUCCESS : EXIT_FAILURE end |