Class: ThemeCheck::Cli
- Inherits:
-
Object
- Object
- ThemeCheck::Cli
- Defined in:
- lib/theme_check/cli.rb
Defined Under Namespace
Classes: Abort
Constant Summary collapse
- USAGE =
"Usage: theme-check [options] /path/to/your/theme\n\nOptions:\n -c, [--category] # Only run this category of checks\n -x, [--exclude-category] # Exclude this category of checks\n -l, [--list] # List enabled checks\n -a, [--auto-correct] # Automatically fix offenses\n -h, [--help] # Show this. Hi!\n -v, [--version] # Print Theme Check version\n\nDescription:\n Theme Check helps you follow Shopify Themes & Liquid best practices by analyzing the\n Liquid & JSON inside your theme.\n\n You can configure checks in the .theme-check.yml file of your theme root directory.\n"
Instance Method Summary collapse
Instance Method Details
#check ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/theme_check/cli.rb', line 78 def check puts "Checking #{@config.root} ..." storage = ThemeCheck::FileSystemStorage.new(@config.root, ignored_patterns: @config.ignored_patterns) theme = ThemeCheck::Theme.new(storage) if theme.all.empty? raise Abort, "No templates found.\n#{USAGE}" end analyzer = ThemeCheck::Analyzer.new(theme, @config.enabled_checks, @config.auto_correct) analyzer.analyze_theme analyzer.correct_offenses ThemeCheck::Printer.new.print(theme, analyzer.offenses, @config.auto_correct) raise Abort, "" if analyzer.uncorrectable_offenses.any? end |
#list ⇒ Object
70 71 72 |
# File 'lib/theme_check/cli.rb', line 70 def list puts @config.enabled_checks end |
#run(argv) ⇒ Object
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 |
# File 'lib/theme_check/cli.rb', line 24 def run(argv) path = "." command = :check only_categories = [] exclude_categories = [] auto_correct = false args = argv.dup while (arg = args.shift) case arg when "--help", "-h" raise Abort, USAGE when "--version", "-v" command = :version when "--category", "-c" only_categories << args.shift.to_sym when "--exclude-category", "-x" exclude_categories << args.shift.to_sym when "--list", "-l" command = :list when "--auto-correct", "-a" auto_correct = true else path = arg end end @config = ThemeCheck::Config.from_path(path) @config.only_categories = only_categories @config.exclude_categories = exclude_categories @config.auto_correct = auto_correct send(command) end |
#run!(argv) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/theme_check/cli.rb', line 60 def run!(argv) run(argv) rescue Abort => e if e..empty? exit(1) else abort(e.) end end |
#version ⇒ Object
74 75 76 |
# File 'lib/theme_check/cli.rb', line 74 def version puts ThemeCheck::VERSION end |