class RFormat::Application
Attributes
args[R]
command[R]
environment[R]
options[R]
Public Class Methods
new(output = $stdout, env = RFormat::Environment.new)
click to toggle source
# File lib/rformat/application.rb, line 22 def initialize(output = $stdout, env = RFormat::Environment.new) @output = output @environment = env @args = Array.try_convert(ARGV) end
Public Instance Methods
help()
click to toggle source
# File lib/rformat/application.rb, line 40 def help @output.puts File.read File.join(RFormat::root_dir, 'HELP.txt') end
list()
click to toggle source
# File lib/rformat/application.rb, line 44 def list @output.puts "Formatters:" @output.puts @environment.formatters.keys.map { |f| " #{f}\n" } end
parse_command()
click to toggle source
# File lib/rformat/application.rb, line 72 def parse_command command = :help if @args.empty? if @args.first && @args.first == 'list' command = :list @args.shift end command = :write if command.nil? @command = command end
parse_options()
click to toggle source
# File lib/rformat/application.rb, line 82 def parse_options @options = {} OptionParser.new do |opts| opts.on("-v", "--version", "Version info") do @options[:version] = true version end opts.on('-h', '--help', 'Display help') do @options[:help] = true help end end.parse! end
run()
click to toggle source
# File lib/rformat/application.rb, line 28 def run parse_command parse_options if @command && @command !~ /^-/ @args.empty? ? self.send(@command) : self.send(@command, @args) else help end end
version()
click to toggle source
# File lib/rformat/application.rb, line 49 def version version = RFormat::Version copyright = RFormat::Copyright @output.puts "#{version}\n#{copyright}" end
write(formats)
click to toggle source
# File lib/rformat/application.rb, line 55 def write(formats) config = { color: true, formats: {} } formats.each do |format| config[:formats][format] = @environment.formatters[format] if @environment.formatters[format] end @environment.config = config if config[:formats].empty? @output.puts "No formatters matching #{formats.join(', ')}" else @environment.write_config @output.puts "rspec now using format(s): #{config[:formats].values.join(', ')}" end end