Skip to content

Commit

Permalink
♻️ Pushed decoration handling to method
Browse files Browse the repository at this point in the history
- Added environment variable handling
- Added decoration handling throughout CLI command handlers
  • Loading branch information
mkarlesky committed May 2, 2024
1 parent ef8f35e commit d4fd63d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 12 deletions.
52 changes: 42 additions & 10 deletions bin/cli_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def setup()
def app_help(env, app_cfg, options, command, &thor_help)
verbosity = @helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

# If help requested for a command, show it and skip listing build tasks
if !command.nil?
# Block handler
Expand Down Expand Up @@ -70,6 +73,9 @@ def rake_help(env:, app_cfg:)
def new_project(env, app_cfg, options, name, dest)
@helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

@path_validator.standardize_paths( dest )

# If destination is nil, reassign it to name
Expand Down Expand Up @@ -123,6 +129,9 @@ def new_project(env, app_cfg, options, name, dest)
def upgrade_project(env, app_cfg, options, path)
@helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

@path_validator.standardize_paths( path, options[:project] )

# Check for existing project
Expand Down Expand Up @@ -161,6 +170,9 @@ def upgrade_project(env, app_cfg, options, path)
def build(env:, app_cfg:, options:{}, tasks:)
@helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

@path_validator.standardize_paths( options[:project], options[:logfile], *options[:mixin] )

_, config = @configinator.loadinate( builtin_mixins:BUILTIN_MIXINS, filepath:options[:project], mixins:options[:mixin], env:env )
Expand All @@ -176,16 +188,9 @@ def build(env:, app_cfg:, options:{}, tasks:)
)

log_filepath = @helper.process_logging( options[:log], options[:logfile] )
if (config[:project] && config[:project][:use_decorators])
case config[:project][:use_decorators]
when :all
@loginator.decorate(true)
when :none
@loginator.decorate(false)
else #includes :auto
#nothing more to do. we've already figured out auto
end
end

# Handle console output of fun characters again now that we also have configuration
@helper.process_decoration( env, config )

# Save references
app_cfg.set_project_config( config )
Expand Down Expand Up @@ -222,10 +227,16 @@ def build(env:, app_cfg:, options:{}, tasks:)
def dumpconfig(env, app_cfg, options, filepath, sections)
@helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

@path_validator.standardize_paths( filepath, options[:project], *options[:mixin] )

_, config = @configinator.loadinate( builtin_mixins:BUILTIN_MIXINS, filepath:options[:project], mixins:options[:mixin], env:env )

# Handle console output of fun characters again now that we also have configuration
@helper.process_decoration( env, config )

# Exception handling to ensure we dump the configuration regardless of config validation errors
begin
# If enabled, process the configuration through Ceedling automatic settings, defaults, plugins, etc.
Expand Down Expand Up @@ -257,10 +268,16 @@ def dumpconfig(env, app_cfg, options, filepath, sections)
def environment(env, app_cfg, options)
@helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

@path_validator.standardize_paths( options[:project], *options[:mixin] )

_, config = @configinator.loadinate( builtin_mixins:BUILTIN_MIXINS, filepath:options[:project], mixins:options[:mixin], env:env )

# Handle console output of fun characters again now that we also have configuration
@helper.process_decoration( env, config )

# Save references
app_cfg.set_project_config( config )

Expand Down Expand Up @@ -302,6 +319,9 @@ def environment(env, app_cfg, options)
def list_examples(env, app_cfg, options)
@helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

# Process which_ceedling for app_cfg modifications but ignore return values
@helper.which_ceedling?( env:env, app_cfg:app_cfg )

Expand All @@ -321,6 +341,9 @@ def list_examples(env, app_cfg, options)
def create_example(env, app_cfg, options, name, dest)
@helper.set_verbosity( options[:verbosity] )

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

@path_validator.standardize_paths( dest )

# Process which_ceedling for app_cfg modifications but ignore return values
Expand Down Expand Up @@ -359,6 +382,9 @@ def create_example(env, app_cfg, options, name, dest)


def version()
# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

require 'ceedling/version'
version = <<~VERSION
Ceedling => #{Ceedling::Version::CEEDLING}
Expand All @@ -375,6 +401,9 @@ def version()
private

def list_rake_tasks(env:, app_cfg:, filepath:nil, mixins:[], silent:false)
# Handle console output of fun characters from environment variable only
@helper.process_decoration( env )

_, config =
@configinator.loadinate(
builtin_mixins:BUILTIN_MIXINS,
Expand All @@ -384,6 +413,9 @@ def list_rake_tasks(env:, app_cfg:, filepath:nil, mixins:[], silent:false)
silent: silent
)

# Handle console output of fun characters from environment variable only
@helper.process_decoration( env, config )

# Save reference to loaded configuration
app_cfg.set_project_config( config )

Expand Down
34 changes: 32 additions & 2 deletions bin/cli_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class CliHelper
constructor :file_wrapper, :actions_wrapper, :config_walkinator, :path_validator, :loginator

def setup
#Aliases
# Aliases
@actions = @actions_wrapper

@loginator.decorate( !windows? )
# Automatic setting of console printing decorations
@loginator.decorate( !windows?() )
end


Expand Down Expand Up @@ -204,6 +205,35 @@ def process_stopwatch(tasks:, default_tasks:)
return !_tasks.empty?
end


def process_decoration(env, config={})
decorate = false

# Environment variable takes precedence
_env = env['CEEDLING_DECORATORS']
if !_env.nil?
if (_env == '1' or _env.strip().downcase() == 'true')
decorate = true
end

@loginator.decorate( decorate )
end

# Otherwise inspect project configuration (could be blank and gets skipped)
walk = @config_walkinator.fetch_value( config, :project, :use_decorators )
if (!walk[:value].nil?)
case walk[:value]
when :all
@loginator.decorate( true )
when :none
@loginator.decorate( false )
else #:auto
# Retain what was set in `setup()` above based on platform
end
end
end


def print_rake_tasks()
Rake.application.standard_exception_handling do
# (This required digging into Rake internals a bit.)
Expand Down

0 comments on commit d4fd63d

Please sign in to comment.