@@ -48,14 +48,16 @@ def initialize(binary_path)
48
48
@last_out = ""
49
49
@last_err = ""
50
50
@last_msg = ""
51
+ @config_dir_hack = false
51
52
end
52
53
53
54
def _wrap_run ( work_fn , *args , **kwargs )
54
55
# do some work to extract & merge environment variables if they exist
55
56
has_env = !args . empty? && args [ 0 ] . instance_of? ( Hash )
56
57
env_vars = has_env ? args [ 0 ] : { }
57
58
actual_args = has_env ? args [ 1 ..-1 ] : args # need to shift over if we extracted args
58
- custom_config = @config_dir . nil? ? [ ] : [ "--config-file" , config_file_cli_param . to_s ]
59
+ custom_config = [ ]
60
+ custom_config += [ "--config-file" , config_file_cli_param . to_s ] unless @config_dir_hack || @config_dir . nil?
59
61
full_args = [ binary_path . to_s , "--format" , "json" ] + custom_config + actual_args
60
62
full_cmd = env_vars . empty? ? full_args : [ env_vars ] + full_args
61
63
@@ -91,12 +93,11 @@ def config_file_path=(rhs)
91
93
92
94
# The config file to be used as a CLI param
93
95
#
94
- # Apparently Linux wants the whole path, and OSX wants just the directory as of 0.29.0,
95
- # it's all very annoying. See unit tests.
96
+ # This format changes based on version, whcih is very annoying. See unit tests.
96
97
#
97
98
# @return [Pathname] the path to use for a given OS
98
99
def config_file_cli_param
99
- OS . osx ? ? @config_dir : config_file_path
100
+ should_use_config_dir ? ? @config_dir : config_file_path
100
101
end
101
102
102
103
# Get an acceptable filename for use as a config file
@@ -307,14 +308,31 @@ def last_bytes_usage
307
308
Hash [ mem_info . names . map ( &:to_sym ) . zip ( mem_info . captures . map ( &:to_i ) ) ]
308
309
end
309
310
311
+ # @return [String] the arduino-cli version that the backend is using, as String
312
+ def version_str
313
+ capture_json ( "version" ) [ :json ] [ "VersionString" ]
314
+ end
315
+
316
+ # @return [Gem::Version] the arduino-cli version that the backend is using, as a semver object
317
+ def version
318
+ Gem ::Version . new ( version_str )
319
+ end
320
+
310
321
private
311
322
312
323
# Since the dry-run behavior became default in arduino-cli 0.14, the command line flag was removed
313
324
# @return [Bool] whether the --dry-run flag is available for this arduino-cli version
314
325
def should_use_dry_run?
315
- ret = capture_json ( "version" )
316
- version = ret [ :json ] [ "VersionString" ]
317
- Gem ::Version . new ( version ) < Gem ::Version . new ( '0.14' )
326
+ version < Gem ::Version . new ( '0.14' )
327
+ end
328
+
329
+ # Since the config dir behavior has changed from a directory to a file (At some point??)
330
+ # @return [Bool] whether to specify configuration by directory or filename
331
+ def should_use_config_dir?
332
+ @config_dir_hack = true # prevent an infinite loop when trying to run the command
333
+ version < Gem ::Version . new ( '0.14' )
334
+ ensure
335
+ @config_dir_hack = false
318
336
end
319
337
end
320
338
end
0 commit comments