Class: Txray::CLI
- Inherits:
-
Object
- Object
- Txray::CLI
- Defined in:
- lib/txray/cli.rb
Constant Summary collapse
- EXIT_CLEAN =
0- EXIT_OFFENSES =
1- EXIT_ERROR =
2
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io: $stdout) ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
Constructor Details
#initialize(io: $stdout) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 |
# File 'lib/txray/cli.rb', line 13 def initialize(io: $stdout) @io = io @options = {} end |
Class Method Details
.start(argv, io: $stdout) ⇒ Object
11 |
# File 'lib/txray/cli.rb', line 11 def self.start(argv, io: $stdout) = new(io: io).run(argv) |
Instance Method Details
#run(argv) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/txray/cli.rb', line 18 def run(argv) paths = parser.parse(argv) return init_config if @options[:init] return watch if paths.first == "watch" config = Config.load(@options[:config]).merge( "fail_level" => @options[:fail_level], "disabled_rules" => @options[:disabled_rules], "max_depth" => @options[:max_depth] ) result = Scanner.new(config, paths: paths).run result = filter(result) Reporters.build(@options.fetch(:format, "text"), io: @io).report(result) result.failing?(config.fail_level) ? EXIT_OFFENSES : EXIT_CLEAN rescue OptionParser::ParseError, Error => e @io.puts "txray: #{e.}" EXIT_ERROR end |