class SyntaxTree::CLI::Options
end.
responsible for parsing the list and then returning the file paths at the
This represents all of the options that can be passed to the CLI. It is
def formatter_options
def formatter_options @formatter_options ||= Formatter::Options.new(target_ruby_version: target_ruby_version) end
def initialize
def initialize @ignore_files = [] @plugins = [] @print_width = DEFAULT_PRINT_WIDTH @scripts = [] @extension = ".rb" @target_ruby_version = DEFAULT_RUBY_VERSION end
def parse(arguments)
def parse(arguments) parser.parse!(arguments) end
def parser
def parser OptionParser.new do |opts| # If there is a glob specified to ignore, then we'll track that here. # Any of the CLI commands that operate on filenames will then ignore # this set of files. opts.on("--ignore-files=GLOB") do |glob| @ignore_files << (glob.match(/\A'(.*)'\z/) ? $1 : glob) end # If there are any plugins specified on the command line, then load # them by requiring them here. We do this by transforming something # like # # stree format --plugins=haml template.haml # # into # # require "syntax_tree/haml" # opts.on("--plugins=PLUGINS") do |plugins| @plugins = plugins.split(",") @plugins.each { |plugin| require "syntax_tree/#{plugin}" } end # If there is a print width specified on the command line, then # parse that out here and use it when formatting. opts.on("--print-width=NUMBER", Integer) do |print_width| @print_width = print_width end # If there is a script specified on the command line, then parse # it and add it to the list of scripts to run. opts.on("-e SCRIPT") { |script| @scripts << script } # If there is a extension specified, then parse it and use it for # STDIN and scripts. opts.on("--extension=EXTENSION") do |extension| # Both ".rb" and "rb" are going to work @extension = ".#{extension.delete_prefix(".")}" end # If there is a target ruby version specified on the command line, # parse that out and use it when formatting. opts.on("--target-ruby-version=VERSION") do |version| @target_ruby_version = Formatter::SemanticVersion.new(version) end end end