lib/scss_beautifier/options.rb in scss_beautifier-0.1.8 vs lib/scss_beautifier/options.rb in scss_beautifier-0.1.10
- old
+ new
@@ -1,89 +1,47 @@
require "optparse"
-module Lintrunner
+module SCSSBeautifier
class Options
attr_reader :options
def initialize
@options = {}
@option_parser = OptionParser.new do |opts|
+ opts.version = SCSSBeautifier::VERSION
add_banner(opts)
add_config_option(opts)
- add_context_option(opts)
- add_include_path_option(opts)
- add_reporter_option(opts)
- add_ignore_option(opts)
- add_colorize_option(opts)
+ add_in_place_option(opts)
end
end
def parse(args)
@option_parser.parse!(args)
- add_defaults
options[:path] = args.first if args.first
options
end
private
- def add_defaults
- options[:config] ||= ".lintrunner_config"
- options[:context] ||= Dir.pwd
- options[:include_paths] = Array(options[:include_paths]) << options[:context]
- options[:include_paths].uniq!
- options[:reporter] ||= "text"
- options[:path] = Dir.pwd
- options[:ignore] ||= []
- end
-
def add_banner(opts)
opts.banner = unindent(<<-BANNER)
- Run multiple linters with various runners
+ Beautify your SCSS code
Usage: #{opts.program_name} [options] [path]
BANNER
end
def add_config_option(opts)
- message = "the configuration file for lintrunner (default: .lintrunner_config)"
+ message = "the configuration file"
opts.on("-c", "--config config", message, String) do |config|
self.options[:config] = config
end
end
- def add_context_option(opts)
- message = "the path on which lintrunner will execute in (default: current path)"
- opts.on("-x", "--context path", message, String) do |path|
- self.options[:context] = Pathname.new(path).realpath.to_s
- end
- end
-
- def add_include_path_option(opts)
- message = "the paths to add to load paths (the context is in the load path)"
- opts.on("--include_path path1,...", message, Array) do |paths|
- self.options[:include_paths] = paths
- end
- end
-
- def add_reporter_option(opts)
- message = "the reporter that lintrunner uses to report results"
- opts.on("--reporter reporter", message, String) do |reporter|
- self.options[:reporter] = reporter
- end
- end
-
- def add_ignore_option(opts)
- message = "the messages to ignore for this lintrunner execution"
- opts.on("--ignore messages", message, Array) do |messages|
- self.options[:ignore] = messages
- end
- end
-
- def add_colorize_option(opts)
- message = "force colorized setting for output"
- opts.on("--colorize", "--[no-]colorize", message) do |bool|
- Rainbow.enabled = bool
+ def add_in_place_option(opts)
+ message = "whether to overwrite the file or not"
+ opts.on("-i", "--in-place", message) do |bool|
+ self.options[:in_place] = bool
end
end
def unindent(str)
str.gsub(/^#{str.scan(/^[ ]+(?=\S)/).min}/, "")
\ No newline at end of file