Class: Prremote::CLI
- Inherits:
-
Thor
- Object
- Thor
- Prremote::CLI
- Defined in:
- lib/prremote/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #deploy(file) ⇒ Object
- #eval(expr) ⇒ Object
- #install ⇒ Object
- #list ⇒ Object
- #reset ⇒ Object
- #run_script(file) ⇒ Object
- #undeploy ⇒ Object
- #version ⇒ Object
- #watch(file) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ 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: [:baud]).call(file) rescue StandardError => e raise Thor::Error, e. 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: [:baud]).call(expr) rescue StandardError => e raise Thor::Error, e. end |
#install ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/prremote/cli.rb', line 28 def install version = [:version] || RUNTIME_VERSION board = [: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. end |
#list ⇒ Object
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 |
#reset ⇒ Object
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, [:baud]) serial.write("\x03") sleep 0.1 puts 'Reset signal sent.' rescue StandardError => e raise Thor::Error, e. 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: [:baud]).call(file) rescue StandardError => e raise Thor::Error, e. end |
#undeploy ⇒ Object
58 59 60 61 62 63 |
# File 'lib/prremote/cli.rb', line 58 def undeploy port = resolve_port Commands::Undeploy.new(port: port, baud: [:baud]).call rescue StandardError => e raise Thor::Error, e. end |
#version ⇒ Object
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.})" end puts "runtime: #{fetch_runtime_version}" end |