Class: Rpremote::FlashCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/rpremote/flash_command.rb,
sig/rpremote.rbs

Class Method Summary collapse

Class Method Details

.run(args, defaults:, output: $stdout, flasher: Flasher) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rpremote/flash_command.rb', line 7

def self.run(args, defaults:, output: $stdout, flasher: Flasher)
  options = parse_options(args, defaults)
  raise ArgumentError, "flash does not accept arguments; use --firmware FILE" unless args.empty?

  target = Target.new(**options.slice(:language, :language_version, :board, :cache_dir, :firmware))
  firmware_path = target.firmware_path(root: Dir.pwd)
  mount = options[:mount] || "an automatically detected RP2350 BOOTSEL volume"
  output.puts("flashing #{firmware_path} to #{mount}; this replaces persistent board firmware")
  result = flasher.new(timeout: options[:timeout]).flash(
    firmware_path,
    mount: options[:mount],
    port: options[:port]
  )
  output.puts("flashed firmware #{File.basename(firmware_path)}: #{result.port}")
end