Skip to content

Commit

Permalink
Restored silent logging option
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
mkarlesky committed Apr 19, 2024
1 parent 8f4da4f commit 579dd44
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions bin/projectinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 )
Expand All @@ -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
Expand Down

0 comments on commit 579dd44

Please sign in to comment.