Class: Herb::Embedded::CLI
- Inherits:
-
Object
- Object
- Herb::Embedded::CLI
- Defined in:
- lib/herb/embedded/cli.rb
Overview
The user-facing entry point (exe/herb-lint-rb). Flags mirror herb-lint; the -rb suffix lets both binaries coexist.
Constant Summary collapse
- EXIT_CLEAN =
0- EXIT_OFFENSES =
1- EXIT_CONFIG_ERROR =
2- VALID_FORMATS =
%w[detailed simple json github].freeze
- VALID_FAIL_LEVELS =
%w[error warning info hint].freeze
- HERB_YML_TEMPLATE =
<<~YAML version: "%<version>s" files: include: - "**/*.html.erb" - "**/*.herb" exclude: [] linter: fail_level: error rules: {} YAML
Instance Method Summary collapse
-
#initialize(argv, stdout:, stderr:) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv, stdout:, stderr:) ⇒ CLI
Returns a new instance of CLI.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/herb/embedded/cli.rb', line 37 def initialize(argv, stdout:, stderr:) @argv = argv.dup @stdout = stdout @stderr = stderr @format = "detailed" @fail_level = nil @only = [] @fix = false @unsafe = false @mode = :lint end |
Instance Method Details
#run ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/herb/embedded/cli.rb', line 49 def run parser.parse!(@argv) case @mode when :help @stdout.puts parser.help EXIT_CLEAN when :version print_version when :init write_init_file else lint_and_report end rescue OptionParser::ParseError => e @stderr.puts e. EXIT_CONFIG_ERROR rescue Psych::SyntaxError => e @stderr.puts "Invalid .herb.yml: #{e.}" EXIT_CONFIG_ERROR end |