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, usage: 64, # Command line usage error data: 65, # User input was incorrect (i.e. contains lints) 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
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/scss_lint/cli.rb', line 8 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/scss_lint/cli.rb', line 8 def @options end |
Instance Method Details
#options_parser ⇒ OptionParser
46 47 48 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 |
# File 'lib/scss_lint/cli.rb', line 46 def @options_parser ||= 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| @options[:config_file] = file end opts.on('-e', '--exclude file,...', Array, 'List of file names to exclude') do |files| @options[:excluded_files] = files end opts.on('-f', '--format Formatter', 'Specify how to display lints', String) do |format| set_output_format(format) end opts.on('-i', '--include-linter linter,...', Array, 'Specify which linters you want to run') do |linters| @options[:included_linters] = linters end opts.on('-x', '--exclude-linter linter,...', Array, "Specify which linters you don't want to run") do |linters| @options[: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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scss_lint/cli.rb', line 27 def parse_arguments begin .parse!(@args) # Take the rest of the arguments as files/directories @options[: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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/scss_lint/cli.rb', line 90 def run runner = Runner.new(@config) runner.run(files_to_lint) report_lints(runner.lints) halt :data if runner.lints.any? 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 '.yellow + BUG_REPORT_URL.cyan halt :software end |