Skip to content

Commit

Permalink
start refactoring to use streaminator for all, and to remove decorato…
Browse files Browse the repository at this point in the history
…rs except when legal.
  • Loading branch information
mvandervoord committed Apr 13, 2024
1 parent 24a0af4 commit 621536d
Show file tree
Hide file tree
Showing 24 changed files with 138 additions and 107 deletions.
2 changes: 1 addition & 1 deletion bin/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def upgrade(path)
\x5 > ceedling build test:all
TASKS are zero or more build operations created from your project configuration.
If no tasks are provided, the built-in default tasks or your :project
If no tasks are provided, the built-in default tasks or your :project ->
:default_tasks will be executed.
Optional Flags:
Expand Down
38 changes: 18 additions & 20 deletions bin/cli_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class CliHandler

constructor :configinator, :projectinator, :cli_helper, :path_validator, :actions_wrapper, :logger
constructor :configinator, :projectinator, :cli_helper, :path_validator, :actions_wrapper, :streaminator

# Override to prevent exception handling from walking & stringifying the object variables.
# Object variables are lengthy and produce a flood of output.
Expand All @@ -24,13 +24,13 @@ def app_help(env, app_cfg, options, command, &thor_help)
# If help requested for a command, show it and skip listing build tasks
if !command.nil?
# Block handler
@logger._print( '🌱 Application ' )
@streaminator.stdout_puts( 'Application ', Verbosity::TITLE )
thor_help.call( command ) if block_given?
return
end

# Display Thor-generated help listing
@logger._print( '🌱 Application ' )
@streaminator.stdout_puts( 'Application ', Verbosity::TITLE )
thor_help.call( command ) if block_given?

# If it was help for a specific command, we're done
Expand Down Expand Up @@ -90,7 +90,7 @@ def new_project(ceedling_root, options, name, dest)
@actions._touch_file( File.join(dest, 'test/support', '.gitkeep') )
end

@logger.log( "\n🌱 New project '#{name}' created at #{dest}/\n" )
@streaminator.stdout_puts( "\nNew project '#{name}' created at #{dest}/\n", Verbosity::TITLE )
end


Expand All @@ -104,7 +104,7 @@ def upgrade_project(ceedling_root, options, path)
end

project_filepath = File.join( path, options[:project] )
_, config = @projectinator.load( filepath:project_filepath, silent:true )
_, config = @projectinator.load( filepath:project_filepath )

if (@helper.which_ceedling?( config ) == 'gem')
msg = "Project configuration specifies the Ceedling gem, not vendored Ceedling"
Expand All @@ -124,7 +124,7 @@ def upgrade_project(ceedling_root, options, path)
@helper.copy_docs( ceedling_root, path )
end

@logger.log( "\n🌱 Upgraded project at #{path}/\n" )
@streaminator.stdout_puts( "\nUpgraded project at #{path}/\n", Verbosity::TITLE )
end


Expand Down Expand Up @@ -200,11 +200,11 @@ def dumpconfig(env, app_cfg, options, filepath, sections)
default_tasks: default_tasks
)
else
@logger.log( " > Skipped loading Ceedling application" )
@streaminator.stdout_puts( " > Skipped loading Ceedling application", Verbosity::OBNOXIOUS )
end
ensure
@helper.dump_yaml( config, filepath, sections )
@logger.log( "\n🌱 Dumped project configuration to #{filepath}\n" )
@streaminator.stdout_puts( "\nDumped project configuration to #{filepath}\n", Verbosity::TITLE )
end
end

Expand Down Expand Up @@ -242,13 +242,13 @@ def environment(env, app_cfg, options)
end
end

output = "\n🌱 Environment variables:\n"
output = "\nEnvironment variables:\n"

env_list.sort.each do |line|
output << " • #{line}\n"
end

@logger.log( output + "\n")
@streaminator.stdout_puts( output + "\n" )
end


Expand All @@ -257,11 +257,11 @@ def list_examples(examples_path)

raise( "No examples projects found") if examples.empty?

output = "\n🌱 Available example projects:\n"
output = "\nAvailable example projects:\n"

examples.each {|example| output << " • #{example}\n" }

@logger.log( output + "\n" )
@streaminator.stdout_puts( output + "\n" )
end


Expand Down Expand Up @@ -294,19 +294,19 @@ def create_example(ceedling_root, examples_path, options, name, dest)
# Copy in documentation
@helper.copy_docs( ceedling_root, dest ) if options[:docs]

@logger.log( "\n🌱 Example project '#{name}' created at #{dest}/\n" )
@streaminator.stdout_puts( "\nExample project '#{name}' created at #{dest}/\n", Verbosity::TITLE )
end


def version()
require 'ceedling/version'
version = <<~VERSION
🌱 Ceedling => #{Ceedling::Version::CEEDLING}
Ceedling => #{Ceedling::Version::CEEDLING}
CMock => #{Ceedling::Version::CMOCK}
Unity => #{Ceedling::Version::UNITY}
CException => #{Ceedling::Version::CEXCEPTION}
VERSION
@logger.log( version )
@streaminator.stdout_puts( version )
end


Expand All @@ -319,21 +319,19 @@ def list_rake_tasks(env:, app_cfg:, filepath:nil, mixins:[])
@configinator.loadinate(
filepath: filepath,
mixins: mixins,
env: env,
silent: true # Suppress project config load logging
env: env
)

# Save reference to loaded configuration
app_cfg[:project_config] = config

@logger.log( "🌱 Build & Plugin Tasks:\n(Parameterized tasks tend to require enclosing quotes and/or escape sequences in most shells)" )
@streaminator.stdout_puts( "Build & Plugin Tasks:\n(Parameterized tasks tend to require enclosing quotes and/or escape sequences in most shells)", Verbosity::TITLE )

@helper.load_ceedling(
project_filepath: project_filepath,
config: config,
which: app_cfg[:which_ceedling],
default_tasks: app_cfg[:default_tasks],
silent: true
default_tasks: app_cfg[:default_tasks]
)

@helper.print_rake_tasks()
Expand Down
22 changes: 11 additions & 11 deletions bin/cli_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class CliHelper

constructor :file_wrapper, :actions_wrapper, :config_walkinator, :path_validator, :logger
constructor :file_wrapper, :actions_wrapper, :config_walkinator, :path_validator, :streaminator

def setup
#Aliases
Expand Down Expand Up @@ -47,10 +47,10 @@ def which_ceedling?(config)
end


def load_ceedling(project_filepath:, config:, which:, default_tasks:[], silent:false)
def load_ceedling(project_filepath:, config:, which:, default_tasks:[])
# Determine which Ceedling we're running
# 1. Copy the which value passed in (most likely a default determined in the first moments of startup)
# 2. If a :project :which_ceedling entry exists in the config, use it instead
# 2. If a :project -> :which_ceedling entry exists in the config, use it instead
_which = which.dup()
walked = @config_walkinator.fetch_value( config, :project, :which_ceedling )
_which = walked[:value] if !walked[:value].nil?
Expand All @@ -70,18 +70,18 @@ def load_ceedling(project_filepath:, config:, which:, default_tasks:[], silent:f
ceedling_path = File.expand_path( ceedling_path )

if !@file_wrapper.directory?( ceedling_path )
raise "Configuration value :project :which_ceedling => '#{_which}' points to a path relative to your project file that contains no Ceedling installation"
raise "Configuration value :project -> :which_ceedling => '#{_which}' points to a path relative to your project file that contains no Ceedling installation"
end

# Otherwise, :which_ceedling is an absolute path
else
if !@file_wrapper.exist?( ceedling_path )
raise "Configuration value :project :which_ceedling => '#{_which}' points to a path that contains no Ceedling installation"
raise "Configuration value :project -> :which_ceedling => '#{_which}' points to a path that contains no Ceedling installation"
end
end

require( File.join( ceedling_path, '/lib/ceedling.rb' ) )
@logger.log( " > Running Ceedling from #{ceedling_path}/" ) if !silent
@streaminator.stdout_puts( " > Running Ceedling from #{ceedling_path}/", Verbosity::OBNOXIOUS )
end

# Set default tasks
Expand Down Expand Up @@ -216,7 +216,7 @@ def dump_yaml(config, filepath, sections)
if walked[:value].nil?
# Reformat list of symbols to list of :<section>s
_sections.map! {|section| ":#{section.to_s}"}
msg = "Cound not find configuration section #{_sections.join(' ')}"
msg = "Cound not find configuration section #{_sections.join(' -> ')}"
raise(msg)
end

Expand Down Expand Up @@ -396,9 +396,9 @@ def vendor_tools(ceedling_root, dest)

private

def windows?
return ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw/) ? true : false) if defined?( RbConfig )
return ((Config::CONFIG['host_os'] =~ /mswin|mingw/) ? true : false)
end
def windows?
return ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw/) ? true : false) if defined?( RbConfig )
return ((Config::CONFIG['host_os'] =~ /mswin|mingw/) ? true : false)
end

end
8 changes: 4 additions & 4 deletions bin/configinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class Configinator

constructor :config_walkinator, :projectinator, :mixinator

def loadinate(filepath:nil, mixins:[], env:{}, silent:false)
def loadinate(filepath:nil, mixins:[], env:{})
# Aliases for clarity
cmdline_filepath = filepath
cmdline_mixins = mixins || []

# Load raw config from command line, environment variable, or default filepath
project_filepath, config = @projectinator.load( filepath:cmdline_filepath, env:env, silent:silent )
project_filepath, config = @projectinator.load( filepath:cmdline_filepath, env:env )

# Extract cfg_enabled_mixins mixins list plus load paths list from config
cfg_enabled_mixins, cfg_load_paths = @projectinator.extract_mixins(
Expand All @@ -36,7 +36,7 @@ def loadinate(filepath:nil, mixins:[], env:{}, silent:false)
if not @projectinator.validate_mixins(
mixins: cfg_enabled_mixins,
load_paths: cfg_load_paths,
source: 'Config :mixins :enabled =>',
source: 'Config :mixins -> :enabled =>',
yaml_extension: yaml_ext
)
raise 'Project configuration file section :mixins failed validation'
Expand Down Expand Up @@ -82,7 +82,7 @@ def loadinate(filepath:nil, mixins:[], env:{}, silent:false)
)

# Merge mixins
@mixinator.merge( config:config, mixins:mixins_assembled, silent:silent )
@mixinator.merge( config:config, mixins:mixins_assembled )

return project_filepath, config
end
Expand Down
12 changes: 0 additions & 12 deletions bin/logger.rb

This file was deleted.

2 changes: 1 addition & 1 deletion bin/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

# Bootloader boom handling
rescue StandardError => e
$stderr.puts( "\n🌱 ERROR: #{e.message}" )
$stderr.puts( "\nERROR: #{e.message}" )
$stderr.puts( e.backtrace ) if ( defined?( PROJECT_DEBUG ) and PROJECT_DEBUG )
exit(1)
end
6 changes: 3 additions & 3 deletions bin/mixinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Mixinator

constructor :path_validator, :yaml_wrapper, :logger
constructor :path_validator, :yaml_wrapper, :streaminator

def setup
# ...
Expand Down Expand Up @@ -80,7 +80,7 @@ def assemble_mixins(config:, env:, cmdline:)
return assembly
end

def merge(config:, mixins:, silent:)
def merge(config:, mixins:)
mixins.each do |mixin|
source = mixin.keys.first
filepath = mixin.values.first
Expand All @@ -97,7 +97,7 @@ def merge(config:, mixins:, silent:)
config.deep_merge( _mixin )

# Log what filepath we used for this mixin
@logger.log( " + Merged #{'(empty) ' if _mixin.empty?}#{source} mixin using #{filepath}" ) if !silent
@streaminator.stdout_puts( " + Merged #{'(empty) ' if _mixin.empty?}#{source} mixin using #{filepath}", Verbosity::DEBUG )
end

# Validate final configuration
Expand Down
38 changes: 29 additions & 9 deletions bin/objects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@
# Loaded from ceedling/lib
file_wrapper:

# Loaded from ceedling/lib
yaml_wrapper:

# Loaded from ceedling/lib
config_walkinator:

actions_wrapper:
stream_wrapper:

system_wrapper:

logger:
verbosinator:

streaminator_helper:

loginator:
compose:
- file_wrapper
- system_wrapper

streaminator:
compose:
- streaminator_helper
- verbosinator
- loginator
- stream_wrapper

# Loaded from bin (here)

actions_wrapper:

# Separation of logic from CLI user interface
cli_handler:
Expand All @@ -20,36 +38,38 @@ cli_handler:
- cli_helper
- path_validator
- actions_wrapper
- logger
- streaminator

cli_helper:
compose:
- file_wrapper
- config_walkinator
- path_validator
- actions_wrapper
- logger
- streaminator

path_validator:
compose:
- file_wrapper
- logger
- streaminator

mixinator:
compose:
- path_validator
- yaml_wrapper
- logger
- streaminator

projectinator:
compose:
- file_wrapper
- path_validator
- yaml_wrapper
- logger
- streaminator

configinator:
compose:
- config_walkinator
- projectinator
- mixinator


Loading

0 comments on commit 621536d

Please sign in to comment.