Class: Amaterasu::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/amaterasu/cli.rb

Overview

Handles arguments parsing when launching the emulator.

Class Method Summary collapse

Class Method Details

.parse(arguments) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
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
# File 'lib/amaterasu/cli.rb', line 8

def self.parse(arguments)
  # @type var options: emulator_options
  options = {
    audio: nil,
    cycles: nil,
    profiling: nil,
    steps: nil,
    trace: nil,
    renderer: nil,
    rom_path: nil
  }

  opt_parser = OptionParser.new do |parser|
    parser.banner = 'Usage: amaterasu [options] ROM_PATH'

    parser.on('-a', '--audio=AUDIO', 'Define the audio backend') do |audio|
      options[:audio] = audio
    end

    parser.on('-c', '--cycles=n', Integer, 'Amount of dots to tick') do |n|
      options[:cycles] = n
    end

    parser.on(
      '-p',
      '--profiling=MODE',
      %w[cpu object wall],
      'Enable Stackprof profiling (cpu, object, wall)'
    ) do |mode|
      options[:profiling] = mode.to_sym
    end

    parser.on('-r', '--renderer=RENDERER', 'Define the renderer backend') do |renderer|
      options[:renderer] = renderer
    end

    parser.on('-s', '--steps=n', Integer, 'Amount of CPU steps to run') do |n|
      options[:steps] = n
    end

    parser.on('-t', '--trace=COMPONENT', 'Enable logging for specific component') do |component|
      options[:trace] = component
    end

    parser.on('-v', '--version', 'Displays the current emulator version') do |component|
      puts Amaterasu::VERSION
      exit(0)
    end
  end

  opt_parser.parse!(arguments)
  options[:rom_path] = arguments.first
  raise ArgumentError, 'ROM_PATH must be provided' unless options[:rom_path]

  options
end