From 579dd44abe29b4e323a82c3db7306ce7917203bc Mon Sep 17 00:00:00 2001 From: Mike Karlesky Date: Fri, 19 Apr 2024 16:37:53 -0400 Subject: [PATCH] Restored silent logging option `load()` should be forced silent in some cases, such as when called by `config_available?()` that just needs to know if a configuration is available --- bin/projectinator.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/projectinator.rb b/bin/projectinator.rb index 4d6fd3aa8..158de24fc 100755 --- a/bin/projectinator.rb +++ b/bin/projectinator.rb @@ -23,10 +23,10 @@ class Projectinator # Returns: # - Absolute path of project file found and used # - Config hash loaded from project file - def load(filepath:nil, env:{}) + def load(filepath:nil, env:{}, silent:false) # Highest priority: command line argument if filepath - config = load_filepath( filepath, 'from command line argument' ) + config = load_filepath( filepath, 'from command line argument', silent ) return File.expand_path( filepath ), config # Next priority: environment variable @@ -35,14 +35,15 @@ def load(filepath:nil, env:{}) @path_validator.standardize_paths( filepath ) config = load_filepath( filepath, - "from environment variable `#{PROJECT_FILEPATH_ENV_VAR}`" + "from environment variable `#{PROJECT_FILEPATH_ENV_VAR}`", + silent ) return File.expand_path( filepath ), config # Final option: default filepath elsif @file_wrapper.exist?( DEFAULT_PROJECT_FILEPATH ) filepath = DEFAULT_PROJECT_FILEPATH - config = load_filepath( filepath, "at default location" ) + config = load_filepath( filepath, "at default location", silent ) return File.expand_path( filepath ), config # If no user provided filepath and the default filepath does not exist, @@ -60,11 +61,11 @@ def load(filepath:nil, env:{}) # - Simplest, default case simply tries to load default project file location. # - Otherwise, attempts to load a filepath, the default environment variable, # or both can be specified. - def config_available?(filepath:nil, env:{}) + def config_available?(filepath:nil, env:{}, silent:true) available = true begin - load(filepath:filepath, env:env) + load(filepath:filepath, env:env, silent:silent) rescue available = false end @@ -189,7 +190,7 @@ def lookup_mixins(mixins:, load_paths:, yaml_extension:) private - def load_filepath(filepath, method) + def load_filepath(filepath, method, silent) begin # Load the filepath we settled on as our project configuration config = @yaml_wrapper.load( filepath ) @@ -199,7 +200,7 @@ def load_filepath(filepath, method) config = {} if config.nil? # Log what the heck we loaded - @streaminator.stream_puts( "Loaded #{'(empty) ' if config.empty?}project configuration #{method} using #{filepath}", Verbosity::DEBUG ) + @streaminator.stream_puts( "Loaded #{'(empty) ' if config.empty?}project configuration #{method} using #{filepath}" ) if !silent return config rescue Errno::ENOENT