Class: N65::FrontEnd
- Inherits:
-
Object
- Object
- N65::FrontEnd
- Defined in:
- lib/n65/front_end.rb
Overview
This class handles the front end aspects,
parsing the commandline and running the assembler
Instance Method Summary collapse
-
#initialize(argv) ⇒ FrontEnd
constructor
Initialize with ARGV commandline.
-
#run ⇒ Object
Run the assembler.
Constructor Details
#initialize(argv) ⇒ FrontEnd
Initialize with ARGV commandline
13 14 15 16 |
# File 'lib/n65/front_end.rb', line 13 def initialize(argv) @options = {:output_file => nil} @argv = argv.dup end |
Instance Method Details
#run ⇒ Object
Run the assembler
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/n65/front_end.rb', line 21 def run ## First use the option parser parser = create_option_parser parser.parse!(@argv) ## Whatever is leftover in argv the input files if @argv.size.zero? STDERR.puts("No input files") exit(1) end ## Only can assemble one file at once for now if @argv.size != 1 STDERR.puts "Can only assemble one input file at once :(" exit(1) end input_file = @argv.shift ## Make sure the input file exists unless File.exists?(input_file) STDERR.puts "Input file #{input_file} does not exist" exit(1) end ## Maybe they didn't provide an output file name, so we'll guess if @options[:output_file].nil? ext = File.extname(input_file) @options[:output_file] = input_file.gsub(ext, '') + '.nes' end if @options.values.any?(&:nil?) STDERR.puts "Missing options try --help" exit(1) end #begin N65::Assembler.from_file(input_file, @options[:output_file]) #rescue StandardError => error #STDERR.puts("Assemble Failed!") #STDERR.puts(error.class) #if error.message #STDERR.puts(error.message) #end #exit(1) #end end |