Skip to content

Commit 3cd45ef

Browse files
authored
Merge pull request #1043 from ThrowTheSwitch/feature/link_notices_in_help
Helpful resources / support links in command line help footer
2 parents c50ff9d + be3e216 commit 3cd45ef

File tree

7 files changed

+105
-24
lines changed

7 files changed

+105
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ _Note:_ Check the [Release Notes][release-notes] for a “cheat sheet” illustr
369369

370370
## Online tutorial
371371

372-
Matt Chernosky’s **[detailed tutorial][tutorial]** demonstrates using Ceedling to build a C project with test suite. As the tutorial is a number of years old, the content is a bit out of date. That said, it provides an excellent overview of a real project. Matt is the author of [FFF] and the [FFF plugin][FFF-plugin] for Ceedling.
372+
Matt Chernosky’s **[detailed tutorial][tutorial]** demonstrates using Ceedling to build a C project with test suite. As the tutorial is a number of years old, the content is a bit out of date. That said, it provides an excellent overview of a real project. Matt is the author of [FFF].
373373

374374
[ceedling-packet]: docs/CeedlingPacket.md
375375
[release-notes]: docs/ReleaseNotes.md

bin/ceedling

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ begin
8888
require 'cli'
8989

9090
# Remove all load paths we've relied on (main application will set up load paths again)
91-
$LOAD_PATH.delete( ceedling_bin_path )
9291
$LOAD_PATH.delete( CEEDLING_APPCFG[:ceedling_lib_path] )
9392
$LOAD_PATH.delete( diy_vendor_path )
9493

bin/cli_handler.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def app_help(env, app_cfg, options, command, &thor_help)
6464
# Silent Ceedling loading unless debug verbosity
6565
silent: !(verbosity == Verbosity::DEBUG)
6666
)
67+
68+
version = @helper.manufacture_app_version( app_cfg )
69+
70+
@helper.help_footer( version.ceedling_tag )
6771
end
6872

6973

@@ -395,10 +399,7 @@ def version(env, app_cfg)
395399
@helper.which_ceedling?( env:env, app_cfg:app_cfg )
396400

397401
# Ceedling application
398-
application = Versionator.new(
399-
app_cfg[:ceedling_root_path],
400-
app_cfg[:ceedling_vendor_path]
401-
)
402+
application = @helper.manufacture_app_version( app_cfg )
402403

403404
# Blank Ceedling version block to be built out conditionally below
404405
ceedling = nil

bin/cli_helper.rb

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# From Ceedling application
1111
require 'ceedling/constants'
1212
require 'ceedling/exceptions'
13+
require 'versionator' # Outisde DIY context
1314

1415
class CliHelper
1516

@@ -21,7 +22,40 @@ def setup
2122
end
2223

2324

24-
def project_exists?( path, op, *components )
25+
def manufacture_app_version(app_cfg)
26+
return Versionator.new(
27+
app_cfg[:ceedling_root_path],
28+
app_cfg[:ceedling_vendor_path]
29+
)
30+
end
31+
32+
33+
def help_footer(ceedling_tag='master')
34+
# Blank line
35+
@loginator.log( "" )
36+
37+
# Documentation incorporating Ceedling version tag in URL
38+
msg = "Ceedling Packet User Manual (v#{ceedling_tag})\n" +
39+
"https://github.com/ThrowTheSwitch/Ceedling/blob/#{ceedling_tag}/docs/CeedlingPacket.md"
40+
@loginator.log( msg, Verbosity::NORMAL, LogLabels::DOCUMENTATION )
41+
42+
# Blank line
43+
@loginator.log( "" )
44+
45+
# Ceedling Suite
46+
msg = "Ceedling Suite can help you do more ➡️ https://www.thingamabyte.com/ceedling"
47+
@loginator.log( msg, Verbosity::NORMAL, LogLabels::COMMERCIAL )
48+
49+
# GitHub Sponsors
50+
msg = "Please consider supporting this work ➡️ https://github.com/sponsors/throwtheswitch"
51+
@loginator.log( msg, Verbosity::NORMAL, LogLabels::REQUEST )
52+
53+
# Blank line
54+
@loginator.log( "" )
55+
end
56+
57+
58+
def project_exists?(path, op, *components)
2559
exists = []
2660

2761
components.each do |f|
@@ -243,12 +277,25 @@ def build_or_plugin_task?(tasks:, default_tasks:)
243277

244278

245279
def print_rake_tasks()
246-
# (This required digging into Rake internals a bit.)
280+
# This all required digging into Rake internals a bit.
281+
282+
# Monkey patch Rake::Application class to prevent writing to $stdout directly
283+
require 'rake_patches'
284+
Rake::Application.include( CaptureHelpOutput )
285+
247286
Rake.application.define_singleton_method(:name=) {|n| @name = n}
248287
Rake.application.name = 'ceedling'
249288
Rake.application.options.show_tasks = :tasks
250289
Rake.application.options.show_task_pattern = /^(?!.*build).*$/
251-
Rake.application.display_tasks_and_comments()
290+
291+
# Use our monkey patched help string accessor instead of Rake's `display_tasks_and_comments()`
292+
rake_tasks = Rake.application.capture_display_tasks()
293+
# Indent task help to match Thow
294+
indentation = ' ' * 2
295+
rake_tasks.gsub!(/^/, indentation)
296+
297+
# Add Rake logging output to our logging handler
298+
@loginator.log( rake_tasks )
252299
end
253300

254301

bin/rake_patches.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'rake'
2+
require 'stringio'
3+
4+
module CaptureHelpOutput
5+
def capture_display_tasks
6+
original_stdout = $stdout
7+
output_string = StringIO.new
8+
$stdout = output_string
9+
10+
begin
11+
# Call the original method that writes directly to $stdout with printf()
12+
display_tasks_and_comments
13+
ensure
14+
# This block will always execute, even if an exception occurs
15+
$stdout = original_stdout
16+
end
17+
18+
# Restore original stdout
19+
$stdout = original_stdout
20+
21+
# Return the captured output
22+
output_string.string
23+
end
24+
end

lib/ceedling/constants.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ class Verbosity
2626

2727
# Label + decorator options for logging
2828
class LogLabels
29-
NONE = 0 # Override logic and settings with no label and no decoration
30-
AUTO = 1 # Default labeling and decorators
31-
NOTICE = 2 # decorator + 'NOTICE:'
32-
WARNING = 3 # decorator + 'WARNING:'
33-
ERROR = 4 # decorator + 'ERROR:'
34-
EXCEPTION = 5 # decorator + 'EXCEPTION:'
35-
CONSTRUCT = 6 # decorator only
36-
RUN = 7 # decorator only
37-
CRASH = 8 # decorator only
38-
PASS = 9 # decorator only
39-
FAIL = 10 # decorator only
40-
TITLE = 11 # decorator only
29+
NONE = 0 # Override logic and settings with no label and no decoration
30+
AUTO = 1 # Default labeling and decorators
31+
NOTICE = 2 # decorator + 'NOTICE:'
32+
WARNING = 3 # decorator + 'WARNING:'
33+
ERROR = 4 # decorator + 'ERROR:'
34+
EXCEPTION = 5 # decorator + 'EXCEPTION:'
35+
CONSTRUCT = 6 # decorator only
36+
RUN = 7 # decorator only
37+
CRASH = 8 # decorator only
38+
PASS = 9 # decorator only
39+
FAIL = 10 # decorator only
40+
TITLE = 11 # decorator only
41+
DOCUMENTATION = 12 # decorator only
42+
COMMERCIAL = 13 # decorator only
43+
REQUEST = 14 # decorator only
4144

4245
# Verbosity levels ERRORS – DEBUG default to certain labels or lack thereof
4346
# The above label constants are available to override Loginator's default AUTO level as needed

lib/ceedling/loginator.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def setup()
3838

3939
@replace = {
4040
# Problematic characters pattern => Simple characters
41-
/↳/ => '>>', # Config sub-entry notation
42-
/•/ => '*', # Bulleted lists
41+
/↳/ => '>>', # Config sub-entry notation
42+
/•/ => '*', # Bulleted lists
43+
/➡️/ => '>>', # Right arrow
4344
}
4445

4546
@project_logging = false
@@ -170,7 +171,7 @@ def log_debug_backtrace(exception)
170171
# Send backtrace to debug logging, formatted almost identically to how Ruby does it.
171172
# Don't log the exception message itself in the first `log()` call as it will already be logged elsewhere
172173
log( "#{exception.backtrace.first}: (#{exception.class})", Verbosity::DEBUG )
173-
log( exception.backtrace.drop(1).map{|s| "\t#{s}"}.join("\n"), Verbosity::DEBUG )
174+
log( exception.backtrace.drop(1).map{|s| "\t#{s}"}.join("\n"), Verbosity::DEBUG )
174175
end
175176

176177

@@ -200,6 +201,12 @@ def decorate(str, label=LogLabels::NONE)
200201
prepend = '❌ '
201202
when LogLabels::TITLE
202203
prepend = '🌱 '
204+
when LogLabels::DOCUMENTATION
205+
prepend = '📝 '
206+
when LogLabels::COMMERCIAL
207+
prepend = '💼 '
208+
when LogLabels::REQUEST
209+
prepend = '🙏 '
203210
end
204211

205212
return prepend + str

0 commit comments

Comments
 (0)