@@ -48,14 +48,16 @@ def initialize(binary_path)
4848 @last_out = ""
4949 @last_err = ""
5050 @last_msg = ""
51+ @config_dir_hack = false
5152 end
5253
5354 def _wrap_run ( work_fn , *args , **kwargs )
5455 # do some work to extract & merge environment variables if they exist
5556 has_env = !args . empty? && args [ 0 ] . instance_of? ( Hash )
5657 env_vars = has_env ? args [ 0 ] : { }
5758 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?
5961 full_args = [ binary_path . to_s , "--format" , "json" ] + custom_config + actual_args
6062 full_cmd = env_vars . empty? ? full_args : [ env_vars ] + full_args
6163
@@ -91,12 +93,11 @@ def config_file_path=(rhs)
9193
9294 # The config file to be used as a CLI param
9395 #
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, which is very annoying. See unit tests.
9697 #
9798 # @return [Pathname] the path to use for a given OS
9899 def config_file_cli_param
99- OS . osx ? ? @config_dir : config_file_path
100+ should_use_config_dir ? ? @config_dir : config_file_path
100101 end
101102
102103 # Get an acceptable filename for use as a config file
@@ -307,14 +308,29 @@ def last_bytes_usage
307308 Hash [ mem_info . names . map ( &:to_sym ) . zip ( mem_info . captures . map ( &:to_i ) ) ]
308309 end
309310
310- private
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
311320
312321 # Since the dry-run behavior became default in arduino-cli 0.14, the command line flag was removed
313322 # @return [Bool] whether the --dry-run flag is available for this arduino-cli version
314323 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' )
324+ version < Gem ::Version . new ( '0.14' )
325+ end
326+
327+ # Since the config dir behavior has changed from a directory to a file (At some point??)
328+ # @return [Bool] whether to specify configuration by directory or filename
329+ def should_use_config_dir?
330+ @config_dir_hack = true # prevent an infinite loop when trying to run the command
331+ version < Gem ::Version . new ( '0.14' )
332+ ensure
333+ @config_dir_hack = false
318334 end
319335 end
320336end
0 commit comments