Class: Tailwindcss::Formatter::CLI
- Inherits:
-
Object
- Object
- Tailwindcss::Formatter::CLI
- Defined in:
- lib/tailwindcss/formatter.rb
Overview
This class handles the command-line interface (CLI) for the TailwindCSS formatter. It processes command-line arguments and passes them to the ClassSorter
Class Method Summary collapse
- .add_check_formatted_option(opts, options) ⇒ Object
- .add_glob_option(opts, options) ⇒ Object
- .add_write_option(opts, options) ⇒ Object
- .find_files(glob) ⇒ Object
- .option_parser(options) ⇒ Object
- .parse_options(argv) ⇒ Object
- .process_files(files, options) ⇒ Object
- .start(argv) ⇒ Object
Class Method Details
.add_check_formatted_option(opts, options) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/tailwindcss/formatter.rb', line 52 def self.add_check_formatted_option(opts, ) opts.on("-c", "--check-formatted [FLAG]", TrueClass, "Raises exit 1 if unformatted class strings are detected (default: false)") do [:check_formatted] = true end end |
.add_glob_option(opts, options) ⇒ Object
40 41 42 43 44 |
# File 'lib/tailwindcss/formatter.rb', line 40 def self.add_glob_option(opts, ) opts.on("-g", "--glob GLOB", "Glob path to match files (default: \"app/**/*.html.erb\")") do |glob| [:glob] = glob end end |
.add_write_option(opts, options) ⇒ Object
46 47 48 49 50 |
# File 'lib/tailwindcss/formatter.rb', line 46 def self.add_write_option(opts, ) opts.on("-w", "--write [FLAG]", TrueClass, "Write any formatting back to the files (default: false)") do [:write] = true end end |
.find_files(glob) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tailwindcss/formatter.rb', line 59 def self.find_files(glob) files = Dir.glob(glob) if files.empty? puts "No files matched the glob pattern: #{glob}" exit 1 end files end |
.option_parser(options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tailwindcss/formatter.rb', line 29 def self.option_parser() OptionParser.new do |opts| opts. = "Usage: tailwindcss-formatter [options]\n Example: tailwindcss-formatter \"app/**/*.html.erb\"" add_glob_option(opts, ) add_write_option(opts, ) add_check_formatted_option(opts, ) end end |
.parse_options(argv) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/tailwindcss/formatter.rb', line 19 def self.(argv) = { glob: "app/**/*.html.erb", check_formatted: false, write: false } # Check if the first argument is a glob pattern (positional argument) [:glob] = argv.shift if argv.any? && !argv.first.start_with?("-") option_parser().parse!(argv) end |
.process_files(files, options) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/tailwindcss/formatter.rb', line 70 def self.process_files(files, ) class_sorter = ClassSorter.new(check_formatted: [:check_formatted], write: [:write]) files.each do |file| class_sorter.process_file(file) end end |
.start(argv) ⇒ Object
13 14 15 16 17 |
# File 'lib/tailwindcss/formatter.rb', line 13 def self.start(argv) = (argv) files = find_files([:glob]) process_files(files, ) end |