theme-check 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b516a7041c1025cd22bcbb4cab685b45893b38fa41ab55b539efad60cf67e100
4
- data.tar.gz: 86d5d5054247c0c86b4a31b066a579fc60fbcf4f0d32940354c4fc9793667498
3
+ metadata.gz: 3c3c0a379dbaa7c43b75d62954952d88a57af1ba6ba028cb30a73803a45fc274
4
+ data.tar.gz: eef366fdb4f66ec0bf33c1d405e405ea757159295a11bac02ea6c8086e9d5342
5
5
  SHA512:
6
- metadata.gz: b76463ad9ecab829705519f163745fdd7cb6dea084558983c914dd3ddf923385050da1c535ad73f48a4442dd8a67bc797fd072e293aa85befb15a141870196db
7
- data.tar.gz: 67571132dcf7fd556c81d4eb7f7e15c8db6c7ccee70384bb6654915090d5c8c213dbbee9b9b36acd74f0cac02390630defe7c1de1956f41f61c9d30294cdd4a0
6
+ metadata.gz: ae494f6e081c0ed351d5511c2990503933b50d2b5749fd33f948770d3ffbb46fb7274b91c164731953e2d3566201b38ed09b352c02ec81091081a70c9697b4b3
7
+ data.tar.gz: 4ecd1ecbc3f035a60c837deb46c8174043a35cc11118fc28f70c30369c8d99d555b4432da1cd3faa662d49773457eb8f3dfad97439a5d2fcce58d45922189ec4
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 0.7.3 / 2021-04-13
3
+ ==================
4
+
5
+ * Refactor CLI option parsing
6
+
2
7
  0.7.2 / 2021-04-12
3
8
  ==================
4
9
 
data/exe/theme-check CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  require "theme_check"
5
5
 
6
- ThemeCheck::Cli.new.run!(ARGV)
6
+ ThemeCheck::Cli.parse_and_run(ARGV)
@@ -1,85 +1,104 @@
1
1
  # frozen_string_literal: true
2
+ require "optparse"
3
+
2
4
  module ThemeCheck
3
5
  class Cli
4
6
  class Abort < StandardError; end
5
7
 
6
- USAGE = <<~END
7
- Usage: theme-check [options] /path/to/your/theme
8
-
9
- Basic Options:
10
- -C, --config <path> Use the config provided, overriding .theme-check.yml if present
11
- -c, --category <category> Only run this category of checks
12
- -x, --exclude-category <category> Exclude this category of checks
13
- -a, --auto-correct Automatically fix offenses
14
-
15
- Miscellaneous:
16
- --init Generate a .theme-check.yml file
17
- --print-config Output active config to STDOUT
18
- -h, --help Show this. Hi!
19
- -l, --list List enabled checks
20
- -v, --version Print Theme Check version
21
-
22
- Description:
23
- Theme Check helps you follow Shopify Themes & Liquid best practices by analyzing the
24
- Liquid & JSON inside your theme.
25
-
26
- You can configure checks in the .theme-check.yml file of your theme root directory.
27
- END
8
+ attr_accessor :path
28
9
 
29
- def run(argv)
10
+ def initialize
30
11
  @path = "."
12
+ @command = :check
13
+ @only_categories = []
14
+ @exclude_categories = []
15
+ @auto_correct = false
16
+ @config_path = nil
17
+ end
31
18
 
32
- command = :check
33
- only_categories = []
34
- exclude_categories = []
35
- auto_correct = false
36
- config_path = nil
37
-
38
- args = argv.dup
39
- while (arg = args.shift)
40
- case arg
41
- when "--help", "-h"
42
- raise Abort, USAGE
43
- when "--version", "-v"
44
- command = :version
45
- when "--config", "-C"
46
- config_path = Pathname.new(args.shift)
47
- when "--category", "-c"
48
- only_categories << args.shift.to_sym
49
- when "--exclude-category", "-x"
50
- exclude_categories << args.shift.to_sym
51
- when "--list", "-l"
52
- command = :list
53
- when "--auto-correct", "-a"
54
- auto_correct = true
55
- when "--init"
56
- command = :init
57
- when "--print"
58
- command = :print
59
- else
60
- @path = arg
61
- end
62
- end
19
+ def option_parser(parser = OptionParser.new, help: true)
20
+ return @option_parser if @option_parser
21
+ @option_parser = parser
22
+ @option_parser.banner = "Usage: theme-check [options] [/path/to/your/theme]"
23
+
24
+ @option_parser.separator("")
25
+ @option_parser.separator("Basic Options:")
26
+ @option_parser.on(
27
+ "-C", "--config PATH",
28
+ "Use the config provided, overriding .theme-check.yml if present"
29
+ ) { |path| @config_path = path }
30
+ @option_parser.on(
31
+ "-c", "--category CATEGORY",
32
+ "Only run this category of checks"
33
+ ) { |category| @only_categories << category.to_sym }
34
+ @option_parser.on(
35
+ "-x", "--exclude-category CATEGORY",
36
+ "Exclude this category of checks"
37
+ ) { |category| @exclude_categories << category.to_sym }
38
+ @option_parser.on(
39
+ "-a", "--auto-correct",
40
+ "Automatically fix offenses"
41
+ ) { @auto_correct = true }
42
+
43
+ @option_parser.separator("")
44
+ @option_parser.separator("Miscellaneous:")
45
+ @option_parser.on(
46
+ "--init",
47
+ "Generate a .theme-check.yml file"
48
+ ) { @command = :init }
49
+ @option_parser.on(
50
+ "--print",
51
+ "Output active config to STDOUT"
52
+ ) { @command = :print }
53
+ @option_parser.on(
54
+ "-h", "--help",
55
+ "Show this. Hi!"
56
+ ) { @command = :help } if help
57
+ @option_parser.on(
58
+ "-l", "--list",
59
+ "List enabled checks"
60
+ ) { @command = :list }
61
+ @option_parser.on(
62
+ "-v", "--version",
63
+ "Print Theme Check version"
64
+ ) { @command = :version }
65
+
66
+ @option_parser.separator("")
67
+ @option_parser.separator(<<~EOS)
68
+ Description:
69
+ Theme Check helps you follow Shopify Themes & Liquid best practices by analyzing the
70
+ Liquid & JSON inside your theme.
71
+
72
+ You can configure checks in the .theme-check.yml file of your theme root directory.
73
+ EOS
74
+
75
+ @option_parser
76
+ end
77
+
78
+ def parse(argv)
79
+ @path = option_parser.parse(argv).first || "."
80
+ end
63
81
 
64
- unless [:version, :init].include?(command)
65
- @config = if config_path
82
+ def run!
83
+ unless [:version, :init, :help].include?(@command)
84
+ @config = if @config_path
66
85
  ThemeCheck::Config.new(
67
86
  root: @path,
68
- configuration: ThemeCheck::Config.load_file(config_path)
87
+ configuration: ThemeCheck::Config.load_file(@config_path)
69
88
  )
70
89
  else
71
90
  ThemeCheck::Config.from_path(@path)
72
91
  end
73
- @config.only_categories = only_categories
74
- @config.exclude_categories = exclude_categories
75
- @config.auto_correct = auto_correct
92
+ @config.only_categories = @only_categories
93
+ @config.exclude_categories = @exclude_categories
94
+ @config.auto_correct = @auto_correct
76
95
  end
77
96
 
78
- send(command)
97
+ send(@command)
79
98
  end
80
99
 
81
- def run!(argv)
82
- run(argv)
100
+ def run
101
+ run!
83
102
  rescue Abort => e
84
103
  if e.message.empty?
85
104
  exit(1)
@@ -88,6 +107,18 @@ module ThemeCheck
88
107
  end
89
108
  end
90
109
 
110
+ def self.parse_and_run!(argv)
111
+ cli = new
112
+ cli.parse(argv)
113
+ cli.run!
114
+ end
115
+
116
+ def self.parse_and_run(argv)
117
+ cli = new
118
+ cli.parse(argv)
119
+ cli.run
120
+ end
121
+
91
122
  def list
92
123
  puts @config.enabled_checks
93
124
  end
@@ -111,12 +142,16 @@ module ThemeCheck
111
142
  puts YAML.dump(@config.to_h)
112
143
  end
113
144
 
145
+ def help
146
+ puts option_parser.to_s
147
+ end
148
+
114
149
  def check
115
150
  puts "Checking #{@config.root} ..."
116
151
  storage = ThemeCheck::FileSystemStorage.new(@config.root, ignored_patterns: @config.ignored_patterns)
117
152
  theme = ThemeCheck::Theme.new(storage)
118
153
  if theme.all.empty?
119
- raise Abort, "No templates found.\n#{USAGE}"
154
+ raise Abort, "No templates found."
120
155
  end
121
156
  analyzer = ThemeCheck::Analyzer.new(theme, @config.enabled_checks, @config.auto_correct)
122
157
  analyzer.analyze_theme
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ThemeCheck
3
- VERSION = "0.7.2"
3
+ VERSION = "0.7.3"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theme-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Cournoyer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-12 00:00:00.000000000 Z
11
+ date: 2021-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid