@@ -20,6 +20,9 @@ def self.flag(name, text = nil)
20
20
attr_accessor :base_cmd
21
21
22
22
attr_reader :library_is_indexed
23
+ attr_reader :last_out
24
+ attr_reader :last_err
25
+ attr_reader :last_msg
23
26
24
27
# set the command line flags (undefined for now).
25
28
# These vary between gui/cli
@@ -32,9 +35,12 @@ def self.flag(name, text = nil)
32
35
flag :verify
33
36
34
37
def initialize
35
- @prefs_cache = { }
36
- @prefs_fetched = false
37
- @library_is_indexed = false
38
+ @prefs_cache = { }
39
+ @prefs_fetched = false
40
+ @library_is_indexed = false
41
+ @last_out = ""
42
+ @last_err = ""
43
+ @last_msg = ""
38
44
end
39
45
40
46
def parse_pref_string ( arduino_output )
@@ -94,9 +100,16 @@ def _run(*args, **kwargs)
94
100
95
101
# build and run the arduino command
96
102
def run ( *args , **kwargs )
97
- # TODO: detect env!!
98
- full_args = @base_cmd + args
99
- _run ( *full_args , **kwargs )
103
+ # do some work to extract & merge environment variables if they exist
104
+ has_env = !args . empty? && args [ 0 ] . class == Hash
105
+ env_vars = has_env ? args [ 0 ] : { }
106
+ actual_args = has_env ? args [ 1 ..-1 ] : args # need to shift over if we extracted args
107
+ full_args = @base_cmd + actual_args
108
+ full_cmd = env_vars . empty? ? full_args : [ env_vars ] + full_args
109
+
110
+ shell_vars = env_vars . map { |k , v | "#{ k } =#{ v } " } . join ( " " )
111
+ @last_msg = " $ #{ shell_vars } #{ full_args . join ( ' ' ) } "
112
+ _run ( *full_cmd , **kwargs )
100
113
end
101
114
102
115
# run a command and capture its output
@@ -113,6 +126,8 @@ def run_and_capture(*args, **kwargs)
113
126
str_err = pipe_err . read
114
127
pipe_out . close
115
128
pipe_err . close
129
+ @last_err = str_err
130
+ @last_out = str_out
116
131
{ out : str_out , err : str_err , success : success }
117
132
end
118
133
@@ -189,11 +204,11 @@ def use_board!(boardname)
189
204
def verify_sketch ( path )
190
205
ext = File . extname path
191
206
unless ext . casecmp ( ".ino" ) . zero?
192
- puts "Refusing to verify sketch with '#{ ext } ' extension -- rename it to '.ino'!"
207
+ @last_msg = "Refusing to verify sketch with '#{ ext } ' extension -- rename it to '.ino'!"
193
208
return false
194
209
end
195
210
unless File . exist? path
196
- puts "Can't verify nonexistent Sketch at '#{ path } '!"
211
+ @last_msg = "Can't verify Sketch at nonexistent path '#{ path } '!"
197
212
return false
198
213
end
199
214
run ( flag_verify , path , err : :out )
@@ -215,11 +230,11 @@ def install_local_library(path)
215
230
# maybe it's a symlink? that would be OK
216
231
if File . symlink? ( destination_path )
217
232
return destination_path if File . readlink ( destination_path ) == realpath
218
- puts "#{ uhoh } and it's not symlinked to #{ realpath } "
233
+ @last_msg = "#{ uhoh } and it's not symlinked to #{ realpath } "
219
234
return nil
220
235
end
221
236
222
- puts "#{ uhoh } . It may need to be removed manually."
237
+ @last_msg = "#{ uhoh } . It may need to be removed manually."
223
238
return nil
224
239
end
225
240
0 commit comments