Class: SCSSLint::CLI
- Inherits:
-
Object
- Object
- SCSSLint::CLI
- Defined in:
- lib/scss_lint/cli.rb
Overview
Responsible for parsing command-line options and executing the appropriate application logic based on the options specified.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args = []) ⇒ CLI
constructor
A new instance of CLI.
- #parse_arguments ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args = []) ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 |
# File 'lib/scss_lint/cli.rb', line 9 def initialize(args = []) @args = args @options = {} end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/scss_lint/cli.rb', line 7 def @options end |
Instance Method Details
#parse_arguments ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/scss_lint/cli.rb', line 14 def parse_arguments parser = OptionParser.new do |opts| opts. = "Usage: #{opts.program_name} [options] [scss-files]" opts.separator '' opts.separator 'Common options:' opts.on('-e', '--exclude file,...', Array, 'List of file names to exclude') do |files| [:excluded_files] = files end opts.on('-i', '--include-linter linter,...', Array, 'Specify which linters you want to run') do |linters| [:included_linters] = linters end opts.on('-x', '--exclude-linter linter,...', Array, "Specify which linters you don't want to run") do |linters| [:excluded_linters] = linters end opts.on_tail('--show-linters', 'Shows available linters') do print_linters end opts.on_tail('-h', '--help', 'Show this message') do print_help opts.help end opts.on_tail('-v', '--version', 'Show version') do print_version opts.program_name, VERSION end opts.on('--xml', 'Output the results in XML format') do [:reporter] = SCSSLint::Reporter::XMLReporter end end begin parser.parse!(@args) # Take the rest of the arguments as files/directories [:files] = @args rescue OptionParser::InvalidOption => ex print_help parser.help, ex end end |
#run ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scss_lint/cli.rb', line 63 def run runner = Runner.new() runner.run(find_files) report_lints(runner.lints) halt(1) if runner.lints? rescue NoFilesError, NoSuchLinter, Errno::ENOENT => ex puts ex. halt(-1) rescue => ex puts ex. puts ex.backtrace puts 'Report this bug at '.yellow + BUG_REPORT_URL.cyan halt(-1) end |