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.
Constant Summary collapse
- EXIT_CODES =
Subset of semantic exit codes conforming to ‘sysexits` documentation.
{ ok: 0, warning: 1, # One or more warnings (but no errors) were reported error: 2, # One or more errors were reported usage: 64, # Command line usage error no_input: 66, # Input file did not exist or was not readable software: 70, # Internal software error config: 78, # Configuration error }
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args = []) ⇒ CLI
constructor
A new instance of CLI.
- #options_parser ⇒ OptionParser
- #parse_arguments ⇒ Object
-
#run ⇒ Object
rubocop:disable MethodLength.
Constructor Details
#initialize(args = []) ⇒ CLI
Returns a new instance of CLI.
24 25 26 27 28 |
# File 'lib/scss_lint/cli.rb', line 24 def initialize(args = []) @args = args = {} @config = Config.default end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/scss_lint/cli.rb', line 10 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/scss_lint/cli.rb', line 10 def end |
Instance Method Details
#options_parser ⇒ OptionParser
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/scss_lint/cli.rb', line 49 def # rubocop:disable MethodLength ||= OptionParser.new do |opts| opts. = "Usage: #{opts.program_name} [options] [scss-files]" opts.separator '' opts.separator 'Common options:' opts.on('-c', '--config file', 'Specify configuration file', String) do |file| [:config_file] = file end opts.on('-e', '--exclude file,...', Array, 'List of file names to exclude') do |files| [:excluded_files] = files end opts.on('-f', '--format Formatter', 'Specify how to display lints', String) do |format| define_output_format(format) end opts.on_tail('--show-formatters', 'Shows available formatters') do print_formatters 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 end end |
#parse_arguments ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/scss_lint/cli.rb', line 30 def parse_arguments begin .parse!(@args) # Take the rest of the arguments as files/directories [:files] = @args rescue OptionParser::InvalidOption => ex print_help .help, ex end begin setup_configuration rescue InvalidConfiguration, NoSuchLinter => ex puts ex. halt :config end end |
#run ⇒ Object
rubocop:disable MethodLength
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/scss_lint/cli.rb', line 97 def run # rubocop:disable MethodLength runner = Runner.new(@config) runner.run(files_to_lint) report_lints(runner.lints) if runner.lints.any?(&:error?) halt :error elsif runner.lints.any? halt :warning end rescue InvalidConfiguration => ex puts ex halt :config rescue NoFilesError, Errno::ENOENT => ex puts ex. halt :no_input rescue NoSuchLinter => ex puts ex. halt :usage rescue => ex puts ex. puts ex.backtrace puts 'Report this bug at '.color(:yellow) + BUG_REPORT_URL.color(:cyan) halt :software end |