Class: Prremote::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/prremote/cli.rb', line 19

def self.exit_on_failure?
  true
end

Instance Method Details

#deploy(file) ⇒ Object



50
51
52
53
54
55
# File 'lib/prremote/cli.rb', line 50

def deploy(file)
  port = resolve_port
  Commands::Deploy.new(port: port, baud: options[:baud]).call(file)
rescue StandardError => e
  raise Thor::Error, e.message
end

#eval(expr) ⇒ Object



66
67
68
69
70
71
# File 'lib/prremote/cli.rb', line 66

def eval(expr)
  port = resolve_port
  Commands::EvalCmd.new(port: port, baud: options[:baud]).call(expr)
rescue StandardError => e
  raise Thor::Error, e.message
end

#installObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/prremote/cli.rb', line 28

def install
  version = options[:version] || RUNTIME_VERSION
  board = options[:board] || 'picow'
  unless RuntimeManager::BOARDS.include?(board)
    raise Thor::Error, "Unknown board '#{board}'. Valid values: #{RuntimeManager::BOARDS.join(', ')}"
  end

  Commands::Install.new(version: version, board: board).call
rescue StandardError => e
  raise Thor::Error, e.message
end

#listObject



82
83
84
85
86
87
88
89
# File 'lib/prremote/cli.rb', line 82

def list
  devices = Detector.new.list_devices
  if devices.empty?
    puts 'No serial devices found.'
  else
    devices.each { |d| puts "#{d[:port]}  (#{d[:label]})" }
  end
end

#resetObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/prremote/cli.rb', line 92

def reset
  port = resolve_port
  serial = Serial.new(port, options[:baud])
  serial.write("\x03")
  sleep 0.1
  puts 'Reset signal sent.'
rescue StandardError => e
  raise Thor::Error, e.message
ensure
  serial&.close
end

#run_script(file) ⇒ Object



41
42
43
44
45
46
# File 'lib/prremote/cli.rb', line 41

def run_script(file)
  port = resolve_port
  Commands::Run.new(port: port, baud: options[:baud]).call(file)
rescue StandardError => e
  raise Thor::Error, e.message
end

#undeployObject



58
59
60
61
62
63
# File 'lib/prremote/cli.rb', line 58

def undeploy
  port = resolve_port
  Commands::Undeploy.new(port: port, baud: options[:baud]).call
rescue StandardError => e
  raise Thor::Error, e.message
end

#versionObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/prremote/cli.rb', line 105

def version
  puts "prremote: #{VERSION}"

  begin
    major = Mrbc.major_version
    puts "mrbc:     #{Mrbc.version} (#{Mrbc.bin})"
    unless major && major >= Mrbc::REQUIRED_MAJOR
      puts "  ** mrbc is too old (need #{Mrbc::REQUIRED_MAJOR}.x) **"
      puts "  Hint: the path can be set via MRBC environment variable."
    end
  rescue StandardError => e
    puts "mrbc:     (#{e.message})"
  end

  puts "runtime:  #{fetch_runtime_version}"
end

#watch(file) ⇒ Object



74
75
76
77
78
79
# File 'lib/prremote/cli.rb', line 74

def watch(file)
  port = resolve_port
  Commands::Watch.new(port: port, baud: options[:baud]).call(file)
rescue StandardError => e
  raise Thor::Error, e.message
end