Skip to content

Conversation

@Tearran
Copy link
Owner

@Tearran Tearran commented Jun 17, 2025

This pull request introduces several improvements and additions to the module management scripts, including the creation of new tools, consolidation of functionality, and refactoring of existing scripts. The changes aim to streamline the module lifecycle, from scaffolding and validation to promotion and consolidation, while removing redundant or outdated scripts.

New Features and Additions:

  • Module Setup Script: Added tools/00_setup_module.sh to create scaffolding for new modules, including .conf, .sh, and .md files in the ./staging directory. This replaces the older staging_00_setup_scaffold.sh script.
  • Module Validation Script: Introduced tools/01_validate_module.sh to validate the presence and completeness of module files (.conf, .sh, and .md) in the ./staging directory.
  • Module Promotion Script: Added tools/03_promote_module.sh to move validated files from ./staging to their appropriate directories (./docs and ./src/<parent>).
  • Module Consolidation Script: Created tools/10_consolidate_module.sh to consolidate .sh files into a single library and generate options arrays from .conf files. This combines and replaces functionality from consolidate_00_lib_src.sh and consolidate_01_lib_metadata.sh.

Refactoring and Cleanup:

  • Removed Redundant Scripts: Deleted older scripts (staging_00_setup_scaffold.sh, staging_01_check_required.sh, staging_03_promote_module.sh, consolidate_00_lib_src.sh, and consolidate_01_lib_metadata.sh) as their functionality has been replaced by the new tools. [1] [2] [3] [4] [5]
  • Embedded Debugging Logic: Moved the debugging test logic directly into src/initialize/debug.sh, removing the need for a separate tests/test_debug.sh script. [1] [2]

Minor Improvements:

  • Help Message Formatting: Adjusted the formatting of help messages in debug.sh for consistency by removing the use of tabs.

Summary by CodeRabbit

  • New Features

    • Introduced scripts to automate module scaffolding, validation, promotion, and consolidation for Armbian Config V3 modules.
    • Added validation to ensure required files and metadata are present and complete before promotion.
    • Automated the movement of module files from staging to their final locations, including documentation handling.
    • Consolidated source and configuration files into unified library files and generated associative arrays for module options and helpers.
  • Bug Fixes

    • Improved formatting and capitalization in generated templates and help messages.
  • Chores

    • Removed obsolete scripts related to legacy staging, consolidation, and validation processes.
    • Updated generated documentation filenames and added placeholders for additional documents.
  • Tests

    • Deleted outdated standalone test scripts, integrating self-tests directly within relevant scripts.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 17, 2025

"""

Walkthrough

This change removes several legacy staging and consolidation scripts, introduces new scripts for module setup, validation, promotion, and consolidation, and updates the module scaffolding process. It also adds a self-test to the debug utility, deletes its standalone test script, and updates generated documentation and script templates for consistency.

Changes

File(s) Change Summary
tools/staging_00_setup_scaffold.sh Expanded default require_os, added helpers variable, updated templates, renamed doc file, improved content.
src/initialize/debug.sh Changed help formatting; added self-test block for runtime verification.
tests/test_debug.sh Deleted Bash test script for debug utility.
tools/consolidate_00_lib_src.sh,
tools/consolidate_01_lib_metadata.sh,
tools/staging_01_check_required.sh,
tools/staging_03_promote_module.sh
Removed legacy scripts for consolidation, staging checks, and promotion.
tools/00_setup_module.sh New script: scaffolds module files with templates for config, script, and docs.
tools/02_validate_module.sh New script: validates presence and completeness of module files in staging.
tools/04_promote_module.sh New script: promotes module files from staging to their final destinations.
tools/06_consolidate_module.sh New script: consolidates source files and generates associative arrays from configs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant 00_setup_module.sh
    participant StagingDir
    participant 02_validate_module.sh
    participant 04_promote_module.sh
    participant SrcDir
    participant DocsDir

    User->>00_setup_module.sh: setup_module <modulename>
    00_setup_module.sh->>StagingDir: Create .conf, .sh, docs_*.md

    User->>02_validate_module.sh: validate_module <modulename>
    02_validate_module.sh->>StagingDir: Check .conf, .sh, docs_*.md

    User->>04_promote_module.sh: promote_module
    04_promote_module.sh->>DocsDir: Move docs_*.md
    04_promote_module.sh->>SrcDir: Move .sh and .conf based on parent
Loading
sequenceDiagram
    participant User
    participant 06_consolidate_module.sh
    participant SrcDir
    participant LibDir

    User->>06_consolidate_module.sh: consolidate_module
    06_consolidate_module.sh->>SrcDir: Read .sh and .conf files
    06_consolidate_module.sh->>LibDir: Write consolidated .sh and arrays
Loading

Possibly related PRs

Poem

In the warren of scripts, a tidy new day,
Old files hop away, new helpers at play.
Modules now scaffolded, checked, and then moved,
With docs and configs neatly improved.
Debug now self-tests with a cheerful "OK!"
🐇✨ Code hops ahead—hip hip hooray!
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tools/staging_00_setup_scaffold.sh (1)

41-42: Align helpers with default override semantics.

All other metadata keys in this template use the ${key:-default} pattern to allow consumer overrides; helpers is currently a static assignment. You might want to support the same override behavior:

-helpers=_about_${MODULE}
+helpers=\${helpers:-_about_${MODULE}}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ca12e7 and 1e03d18.

📒 Files selected for processing (1)
  • tools/staging_00_setup_scaffold.sh (1 hunks)

deleted:    tests/test_debug.sh
modified:   tools/consolidate_00_lib_src.sh
modified:   tools/consolidate_01_lib_metadata.sh
modified:   tools/staging_00_setup_scaffold.sh
modified:   tools/staging_01_check_required.sh
modified:   tools/staging_03_promote_module.sh
@Tearran Tearran marked this pull request as draft June 17, 2025 15:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (8)
src/initialize/debug.sh (3)

38-49: Review here-document delimiter in _about_debug
The change from <<-EOF to <<EOF removes leading-tab stripping, so any tabs before help lines will be retained. Consider either switching back to <<-EOF (to allow indented here-docs) or removing all tabs and left-aligning the help text.


58-63: Simplify assertion with shell built-in
Instead of spawning grep, you can use a shell pattern match:

if [[ "$help_output" != *"Usage: debug"* ]]; then
  echo "Help output does not contain expected usage string"
  exit 1
fi

This avoids an external process and streamlines the self-test.


66-69: Preserve help text formatting and isolate debug output
Using debug "$help_output" treats the entire multi-line help text as a single cmd and runs it through the elapsed-time formatter, which mangles the layout. Also, test and debug messages on stdout can interfere with consumers of the script’s output. Update to:

- debug "$help_output"
+ echo "$help_output" >&2

And consider redirecting the other debug/printf calls in the self-test to stderr (>&2).

tools/consolidate_01_lib_metadata.sh (2)

10-10: Unused IGNORE_FILES variable
IGNORE_FILES is declared but never referenced. Remove it or implement its intended ignore logic to avoid confusion.


12-12: Duplicate directory creation
The mkdir -p "$LIB_ROOT" here duplicates the later mkdir -p "$(dirname "$OUT_FILE")". Consider removing the early call to DRY up the code.

tools/staging_03_promote_module.sh (3)

8-9: Remove unused declarations
array_entries and group_counts are declared but never used in this script—drop them to reduce noise.


13-14: Fix comment to match file extension
The comment refers to docs_*.sh but the loop processes docs_*.md. Update the comment to reflect .md.


20-22: Review skip condition for docs files
Since the for sh_file loop only matches *.sh, the *docs_*.sh check is redundant. If you intended to exclude docs .md, adjust the pattern or remove this branch.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e03d18 and b05c568.

📒 Files selected for processing (7)
  • src/initialize/debug.sh (1 hunks)
  • tests/test_debug.sh (0 hunks)
  • tools/consolidate_00_lib_src.sh (1 hunks)
  • tools/consolidate_01_lib_metadata.sh (1 hunks)
  • tools/staging_00_setup_scaffold.sh (3 hunks)
  • tools/staging_01_check_required.sh (4 hunks)
  • tools/staging_03_promote_module.sh (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/test_debug.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/staging_00_setup_scaffold.sh
🧰 Additional context used
📓 Path-based instructions (1)
`src/**/*.sh`: Shell script review: - Proper variable quoting - Portable shell features - Security considerations - Error handling patterns

src/**/*.sh: Shell script review:

  • Proper variable quoting
  • Portable shell features
  • Security considerations
  • Error handling patterns
  • src/initialize/debug.sh
🪛 Shellcheck (0.10.0)
tools/staging_01_check_required.sh

[warning] 38-38: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

tools/staging_03_promote_module.sh

[warning] 8-8: array_entries appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 9-9: group_counts appears unused. Verify use (or export if used externally).

(SC2034)

tools/consolidate_01_lib_metadata.sh

[warning] 10-10: IGNORE_FILES appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (8)
tools/consolidate_01_lib_metadata.sh (1)

9-9: Approve addition of LIB_ROOT
Creating LIB_ROOT centralizes the library output path for metadata arrays.

tools/consolidate_00_lib_src.sh (1)

2-2: Enable strict mode (-euo pipefail)
Good enhancement for robust error handling—make sure downstream code handles unset variables and pipeline failures under this stricter mode.

tools/staging_01_check_required.sh (4)

16-23: Update required files to include .conf and drop tests
Aligns with scaffold changes: only ${module}.sh and ${module}.conf are now mandatory.


26-31: Align optional docs filename
Switched from doc_${module}.md to docs_${module}.md, matching new conventions.


36-45: Rename main function to check_required and refine output
Function name and output formatting now mirror other staging scripts.


56-58: Invoke the updated check_required function
Ensures standalone execution with the new function name.

tools/staging_03_promote_module.sh (2)

5-7: Create documentation output directory
Initializing DOC_ROOT and ensuring it exists is correct.


31-35: Approve moving logic for scripts and config
The block correctly moves both the .sh and its .conf into src/$parent with clear messaging.

Tearran added 2 commits June 17, 2025 16:41
modified:   tools/staging_03_promote_module.sh
…0_setup_module.sh

validate_modulenew file:   tools/01_validate_module.sh
validate_modulerenamed:    tools/staging_03_promote_module.sh -> tools/03_promote_module.sh
validate_modulenew file:   tools/10_consolidate_module.sh
validate_moduledeleted:    tools/consolidate_00_lib_src.sh
validate_moduledeleted:    tools/consolidate_01_lib_metadata.sh
validate_moduledeleted:    tools/staging_01_check_required.sh
@Tearran Tearran changed the title modified: tools/staging_00_setup_scaffold.sh @coderabbitai Jun 17, 2025
@Tearran Tearran marked this pull request as ready for review June 17, 2025 19:16
@coderabbitai coderabbitai bot changed the title @coderabbitai Update scaffold templates, metadata, and staging scripts with naming and debug changes Jun 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (10)
tools/00_setup_module.sh (3)

24-24: Remove trailing whitespace.

Line 24 has trailing spaces, which fails the style check.


63-90: Make generated module script executable.

Currently the scaffolded ${MODULE}.sh is not marked executable. Add a chmod +x after creation so the new module can be run immediately.

Example diff:

   cat > "${STAGING_DIR}/${MODULE}.sh" <<EOF
   #!/bin/bash
   set -euo pipefail
   ...
   EOF
+  chmod +x "${STAGING_DIR}/${MODULE}.sh"

95-95: Remove trailing whitespace.

Line 95 ends with an extra space, causing a style error.

tools/03_promote_module.sh (3)

6-6: Remove trailing whitespace.

Line 6 contains trailing spaces and incorrect line endings; please strip whitespace and ensure a final newline.


10-11: Drop unused array declarations.

array_entries and group_counts are declared but never used in this script. Removing them will eliminate dead code and ShellCheck warnings.

-   declare -A array_entries
-   declare -A group_counts  # For unique id per group

14-14: Correct comment typo.

The comment reads “Move docs_*.sh scripts” but the script handles docs_*.md files. Update for clarity.

tools/01_validate_module.sh (2)

1-1: Fix line endings and add final newline.

The script starts with wrong line endings and no trailing newline. Convert to Unix LF and ensure a final newline to satisfy the style check.


54-55: Clarify or remove outdated comment.

The comment “# At top of your script” above REQUIRED_CONF_FIELDS is misleading in this context. Consider updating or removing it.

tools/10_consolidate_module.sh (2)

1-1: Fix line endings and add final newline.

The shebang line has incorrect line endings and the file lacks a trailing newline. Convert to Unix LF and append a newline.


85-86: Scope section_kv to its function.

section_kv is declared globally but only used inside _process_confs(). Mark it local to avoid potential conflicts and satisfy stricter shellcheck settings.

 _process_confs() {
-   declare -A section_kv=()
+   local -A section_kv=()
     ...
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b05c568 and b537d66.

📒 Files selected for processing (8)
  • tools/00_setup_module.sh (1 hunks)
  • tools/01_validate_module.sh (1 hunks)
  • tools/03_promote_module.sh (1 hunks)
  • tools/10_consolidate_module.sh (1 hunks)
  • tools/consolidate_00_lib_src.sh (0 hunks)
  • tools/consolidate_01_lib_metadata.sh (0 hunks)
  • tools/staging_01_check_required.sh (0 hunks)
  • tools/staging_03_promote_module.sh (0 hunks)
💤 Files with no reviewable changes (4)
  • tools/staging_03_promote_module.sh
  • tools/consolidate_00_lib_src.sh
  • tools/staging_01_check_required.sh
  • tools/consolidate_01_lib_metadata.sh
🧰 Additional context used
🪛 GitHub Actions: 01 Coding style check
tools/00_setup_module.sh

[error] 24-24: Wrong line endings or no final newline; Trailing whitespace at line 24.


[error] 95-95: Trailing whitespace at line 95.

tools/03_promote_module.sh

[error] 6-6: Wrong line endings or no final newline; Trailing whitespace at line 6.

tools/01_validate_module.sh

[error] 1-1: Wrong line endings or no final newline.

tools/10_consolidate_module.sh

[error] 1-1: Wrong line endings or no final newline.

🪛 Shellcheck (0.10.0)
tools/03_promote_module.sh

[warning] 10-10: array_entries appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 11-11: group_counts appears unused. Verify use (or export if used externally).

(SC2034)

tools/10_consolidate_module.sh

[warning] 95-95: section_kv appears unused. Verify use (or export if used externally).

(SC2034)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
tools/03_promote_module.sh (2)

10-11: Remove unused variable declarations
array_entries and group_counts are declared but never used in this script. Removing them reduces confusion and silences ShellCheck warnings.

- declare -A array_entries
- declare -A group_counts  # For unique id per group

21-27: Extract the staging directory into a variable
Hard-coding ./staging reduces flexibility. Consider defining STAGING_DIR="${STAGING_DIR:-./staging}" at the top and using it in both loops.

tools/10_consolidate_module.sh (1)

1-5: Add a Bash version check for declare -n
The script relies on name references (declare -n), which require Bash ≥4.3. Add an early version check to fail on older Bash versions:

if (( BASH_VERSINFO[0] < 4 || ( BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] < 3 ) )); then
  echo "Error: Bash 4.3+ is required to run this script." >&2
  exit 1
fi
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b537d66 and 634af85.

📒 Files selected for processing (4)
  • tools/00_setup_module.sh (1 hunks)
  • tools/01_validate_module.sh (1 hunks)
  • tools/03_promote_module.sh (1 hunks)
  • tools/10_consolidate_module.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tools/00_setup_module.sh
  • tools/01_validate_module.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
tools/10_consolidate_module.sh

[warning] 95-95: section_kv appears unused. Verify use (or export if used externally).

(SC2034)

tools/03_promote_module.sh

[warning] 10-10: array_entries appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 11-11: group_counts appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (1)
tools/10_consolidate_module.sh (1)

95-95: Skip false positive SC2034 for section_kv
section_kv is passed by name to emit_section and consumed there; the ShellCheck SC2034 warning can be safely ignored.

Tearran and others added 3 commits June 17, 2025 19:22
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
tools/03_promote_module.sh (5)

7-7: Introduce STAGE_ROOT and SRC_ROOT variables for flexibility
Instead of hard-coding ./staging and ./src, define defaults like:

STAGE_ROOT="${STAGE_ROOT:-./staging}"
SRC_ROOT="${SRC_ROOT:-./src}"

and use them throughout to allow overrides.


14-14: Fix comment to match code behavior
The comment mentions docs_*.sh but the glob is docs_*.md. Update it to:

-# Move docs_*.sh scripts from staging to docs/
+# Move docs_*.md files from staging to docs/

21-23: Remove redundant skip for docs_*.sh
The condition [[ "$sh_file" == *docs_*.sh ]] will never match since the glob is limited to *.sh and docs files use .md. You can safely remove this check.


28-29: Robustly parse parent= in .conf
Consider using a pipeline that handles whitespace and inline comments, e.g.:

parent=$(grep -m1 '^parent=' "$conf_file" | cut -d'=' -f2- | tr -d ' ')

30-34: Use $SRC_ROOT variable for destination
To respect overrides, replace the hard-coded ./src/$parent with "$SRC_ROOT/$parent".

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd50486 and b2cf73e.

📒 Files selected for processing (2)
  • tools/00_setup_module.sh (1 hunks)
  • tools/03_promote_module.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/00_setup_module.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
tools/03_promote_module.sh

[warning] 10-10: array_entries appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 11-11: group_counts appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (3)
tools/03_promote_module.sh (3)

1-2: Use of strict mode is appropriate
The shebang and set -euo pipefail provide robust error handling.


15-19: Docs loop correctly moves Markdown files
The loop safely checks existence and moves docs_*.md to $DOC_ROOT. Good use of -f and quoting.


43-45: Correct use of execution guard
The check against BASH_SOURCE[0] ensures promote_module only runs when the script is executed directly. This pattern is correctly implemented.

@Tearran Tearran requested a review from Copilot June 17, 2025 20:55

This comment was marked as outdated.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tools/10_consolidate_module.sh (1)

104-112: Consider replacing echo -e with printf for portability
While Bash’s echo -e works here, printf is more predictable across environments.

- echo -e "######## Auto-generated. Do not edit. ########\n"
+ printf "######## Auto-generated. Do not edit. ########\n\n"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b943b5f and fdacb4a.

📒 Files selected for processing (1)
  • tools/10_consolidate_module.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
tools/10_consolidate_module.sh

[warning] 95-95: section_kv appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (9)
tools/10_consolidate_module.sh (9)

1-11: Strict mode and globals setup
Utilizing set -euo pipefail with clearly defined SRC_ROOT, OUT_FILE, and ignore lists establishes a robust foundation for the script.


12-17: Helper and counter arrays initialization
Declaring array_entries, group_counts, and the required_helper_keys upfront enhances readability and enforceability of metadata rules.


18-45: Consolidate source files logic is clear
Function _consolidate_src properly iterates subdirectories, skips ignored files, strips shebangs, and aggregates module scripts.


47-78: Metadata emission logic is sound
emit_section correctly validates required helper keys, computes unique IDs, and appends key/value pairs into the appropriate associative arrays.


80-100: Configuration parsing loop is robust
Function _process_confs reads .conf files section-by-section, handles comments, and ensures the last section is emitted.


85-95: False positive: 'section_kv' flagged as unused
Although ShellCheck raises SC2034, section_kv is passed by nameref to emit_section and used indirectly. This warning can be safely ignored.


102-114: Array writing implementation is reliable
_write_arrays writes sorted associative arrays with clear start/finish markers, promoting maintainability of the generated file.


116-135: Command dispatcher covers expected workflows
consolidate_module cleanly handles consolidate, generate/process, and all modes with a helpful usage message.


138-141: Self-execution guard is correct
The check on ${BASH_SOURCE[0]} ensures the script runs its default behavior only when invoked directly.

@Tearran Tearran requested a review from Copilot June 18, 2025 03:15

This comment was marked as outdated.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
tools/10_consolidate_module.sh (5)

18-48: Refine directory traversal & output formatting

  • Add a guard to skip non-directories in the loop to avoid a literal glob when no subdirs exist.
  • Prefer printf over echo -e for portability.
  • Minor grammar tweak in the success message.

Example diff:

@@ -20,6 +20,7 @@ _consolidate_src() {
     for DIR in "$SRC_ROOT"/*/; do
+        [[ -d "$DIR" ]] || continue
         local NS OUT f fname skip relpath
         NS=$(basename "$DIR")
         OUT="$LIB_ROOT/$NS.sh"
@@ -42,4 +43,5 @@ _consolidate_src() {
-            echo -e "\n####### $relpath #######" >> "$OUT"
-            sed '1{/^#!.*bash/d}' "$f" >> "$OUT"
-            echo -e "\n" >> "$OUT"
+            printf '\n####### %s #######\n' "$relpath" >> "$OUT"
+            sed '1{/^#!.*bash/d}' "$f" >> "$OUT"
+            printf '\n' >> "$OUT"
     done
-echo "All library files have assembled in $LIB_ROOT/"
+    echo "All library files have been assembled in $LIB_ROOT/"
 }

50-81: Improve determinism and enforce naming constraints

  • Sort mapref keys before iteration to guarantee consistent array output order.
  • (Optional) Validate that parent conforms to Bash identifier rules to avoid invalid variable declarations.

Example diff for key sorting:

@@ emit_section() {
-   for key in "${!mapref[@]}"; do
+   # Ensure consistent order of metadata entries
+   local keys=($(printf '%s\n' "${!mapref[@]}" | sort))
+   for key in "${keys[@]}"; do

105-117: Enhance output reliability with printf
Replace the echo "${array_entries[$arr]}" call with printf '%s\n' to ensure embedded newlines and special characters are preserved exactly.

@@ _write_arrays() {
-           echo "${array_entries[$arr]}"
+           printf '%s\n' "${array_entries[$arr]}"

119-139: Refine usage error handling & CLI UX

  • Send the usage message to stderr when an invalid command is provided.
  • Consider adding a --help/-h flag for explicit usage guidance.

Example diff:

@@ *) 
-           echo "Usage: $0 [consolidate|generate|all]"
+           echo "Usage: $0 [consolidate|generate|all]" >&2
            return 1

141-144: Remove or implement the unused DEBUG variable
The DEBUG variable is assigned but never used. Either drop it or leverage it (e.g., toggle set -x).

@@ -142,2 +142,3 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
-    DEBUG="${DEBUG:-}"
+    # Enable debug output if DEBUG is set
+    [[ -n "$DEBUG" ]] && set -x
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fdacb4a and 692d672.

📒 Files selected for processing (1)
  • tools/10_consolidate_module.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
tools/10_consolidate_module.sh

[warning] 98-98: section_kv appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (2)
tools/10_consolidate_module.sh (2)

5-11: Strict mode and variable initialization are solid.
The use of set -euo pipefail ensures robust failure handling, and initial vars (SRC_ROOT, OUT_FILE, LIB_ROOT, IGNORE_FILES) are clearly defined.


83-103: ShellCheck SC2034 false positive – skip
The section_kv array is passed by reference into emit_section, so it is used implicitly. No action needed.

renamed:    tools/01_validate_module.sh -> tools/02_validate_module.sh
renamed:    tools/03_promote_module.sh -> tools/04_promote_module.sh
renamed:    tools/10_consolidate_module.sh -> tools/06_consolidate_module.sh
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (7)
tools/06_consolidate_module.sh (4)

1-14: Consider marking constants as readonly.

The path and ignore-file variables (SRC_ROOT, OUT_FILE, LIB_ROOT, IGNORE_FILES) are effectively constants. Declaring them as readonly can prevent accidental reassignment and improve clarity.


18-48: Prefer printf over echo -e and document the sed trick.

Relying on echo -e is less portable across shells. Using printf ensures consistent interpretation of escape sequences. Also, the sed '1{/^#!.*bash/d}' command removes the shebang—consider adding an inline comment to explain its intent.

Example diff:

-for f in "$DIR"/*.sh; do
+for f in "$DIR"/*.sh; do
     [[ -e "$f" ]] || continue
     fname=$(basename "$f")
     skip=false
     for ignore in "${IGNORE_FILES[@]}"; do
         if [[ "${fname,,}" == "${ignore,,}" ]]; then
             skip=true
             break
         fi
     done

     if [[ "$skip" == true ]]; then
         continue
     fi

     relpath="${DIR%/}/$fname"
-    echo -e "\n####### $relpath #######" >> "$OUT"
-    sed '1{/^#!.*bash/d}' "$f" >> "$OUT"
-    echo -e "\n" >> "$OUT"
+    printf "\n####### %s #######\n" "$relpath" >> "$OUT"
+    # remove existing shebang from source
+    sed '1{/^#!.*bash/d}' "$f" >> "$OUT"
+    printf "\n" >> "$OUT"
 done

50-81: Escape values when emitting array entries.

Embedding raw config values may break if they contain quotes or backslashes. Consider using printf '%q' or another escaping mechanism to safely serialize each mapref[$key].


105-117: Prefer printf for multi-line output in _write_arrays.

Using echo -e can behave inconsistently; printf offers clearer semantics:

-    echo -e "######## Auto-generated. Do not edit. ########\n"
+    printf "######## Auto-generated. Do not edit. ########\n\n"
tools/04_promote_module.sh (1)

15-19: Handle empty globs or enable nullglob.

If no docs_*.md files exist, the glob expands to the literal pattern. To avoid spurious iterations, either enable shopt -s nullglob at the top of the function or guard more strictly:

+shopt -s nullglob
 for docs_file in ./staging/docs_*.md; do
     [ -f "$docs_file" ] || continue
     echo "Moving $docs_file to $DOC_ROOT/"
     mv "$docs_file" "$DOC_ROOT/"
 done
+shopt -u nullglob
tools/02_validate_module.sh (2)

4-20: Use <<-EOF to preserve indentation in help message.

Switching to a here-doc with <<-EOF allows the help text to be indented cleanly without injecting leading tabs:

-_about_validate_module() {
-  cat <<EOF
+_about_validate_module() {
+  cat <<-EOF

54-56: Consider anchoring field checks to avoid false positives.

Current _check_conf uses grep -qE "^$field=", which may match prefixes (feature_extra=). To avoid this, you can anchor the field name:

-for field in "${REQUIRED_CONF_FIELDS[@]}"; do
-  if ! grep -qE "^$field=" "$file"; then
+for field in "${REQUIRED_CONF_FIELDS[@]}"; do
+  if ! grep -qE "^${field}=" "$file"; then
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 692d672 and c5b5b77.

📒 Files selected for processing (4)
  • tools/00_setup_module.sh (1 hunks)
  • tools/02_validate_module.sh (1 hunks)
  • tools/04_promote_module.sh (1 hunks)
  • tools/06_consolidate_module.sh (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tools/00_setup_module.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
tools/04_promote_module.sh

[warning] 10-10: array_entries appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 11-11: group_counts appears unused. Verify use (or export if used externally).

(SC2034)

tools/06_consolidate_module.sh

[warning] 98-98: section_kv appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (9)
tools/06_consolidate_module.sh (3)

50-81: Verify Bash version for declare -n nameref usage.

The emit_section function uses declare -n to create a nameref. That feature requires Bash ≥ 4.3. Please confirm that the target environment runs a compatible Bash version, or add a version check at the top of the script.


83-103: Skip false-positive ShellCheck warning for section_kv.

section_kv is used via a Bash nameref (declare -n mapref), so ShellCheck’s SC2034 (“unused variable”) is a false positive here. No action needed.


119-139: Consolidation entry point is solid.

The consolidate_module function cleanly handles subcommands and defaults to all. The case structure and direct-execution guard are correctly implemented.

tools/04_promote_module.sh (3)

22-39: Script promotion logic is well-structured.

The loop correctly skips non-matching files, extracts parent from .conf, and moves both the script and its config atomically. Error messages for missing parent are clear.


43-45: Direct-execution guard is correct.

Using if [[ "${BASH_SOURCE[0]}" == "${0}" ]] ensures promote_module only runs when the script is invoked directly.


10-11: Remove unused associative arrays.

The declarations declare -A array_entries and declare -A group_counts are never referenced in this script. Removing them will reduce confusion and eliminate dead code.

⛔ Skipped due to learnings
Learnt from: Tearran
PR: Tearran/configng-v2#25
File: tools/03_promote_module.sh:10-11
Timestamp: 2025-06-17T20:56:24.174Z
Learning: The arrays `array_entries` and `group_counts` declared in `tools/03_promote_module.sh` are actually used by `tools/10_consolidate_module.sh`, indicating these scripts work together in the module management workflow.
tools/02_validate_module.sh (3)

22-38: Markdown validation logic is solid.

The _check_md function correctly identifies missing files, missing headers, and header-only documents. The checks are clear and comprehensive.


40-52: Shell script check is accurate.

Using grep to detect the _about_<modulename>() function ensures each script includes its help stub. The pattern is correct under POSIX-basic regex.


95-98: Direct-execution guard is implemented correctly.

The check ensures validate_module only runs when the script is called directly, which is standard practice.

@Tearran Tearran requested a review from Copilot June 18, 2025 04:30

This comment was marked as outdated.

modified:   tools/04_promote_module.sh
@Tearran Tearran requested a review from Copilot June 18, 2025 04:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors and consolidates module management scripts by removing legacy scripts and introducing new ones with enhanced scaffolding, validation, promotion, and consolidation functionality. The changes improve the naming conventions, integrate debugging tests directly into the source, and streamline the module lifecycle.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/staging_03_promote_module.sh Removed legacy promote script.
tools/staging_01_check_required.sh Removed obsolete module file check script.
tools/staging_00_setup_scaffold.sh Removed deprecated scaffold setup script.
tools/consolidate_01_lib_metadata.sh Removed legacy metadata consolidation script.
tools/consolidate_00_lib_src.sh Removed legacy library source consolidation script.
tools/06_consolidate_module.sh Added new consolidation script combining source and configuration processing.
tools/04_promote_module.sh Added updated promotion script moving files from staging to appropriate destinations.
tools/02_validate_module.sh Added module validation with clear output statuses.
tools/00_setup_module.sh Added updated module scaffold setup script with integrated metadata, module, and documentation generation.
tests/test_debug.sh Removed outdated standalone debug tests in favor of embedded debug logic in the initialize script.
src/initialize/debug.sh Updated debug script with improved help message formatting and inline testing logic.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
tools/04_promote_module.sh (1)

12-12: Update misleading comment

The comment refers to docs_*.sh although documentation files are .md. Update it to accurately reflect the action.

Example:

-# Move *.sh (not docs_*.sh) with a matching .conf file to src/$parent/
+# Move staging .sh files with a matching .conf file to src/$parent/
🧹 Nitpick comments (1)
tools/04_promote_module.sh (1)

13-29: Scope parent variable locally

parent is assigned inside the loop but not declared local, which can leak its value outside the loop and cause cross-contamination between loops. Declare it as local.

Example:

-for sh_file in ./staging/*.sh; do
+for sh_file in ./staging/*.sh; do
     [ -f "$sh_file" ] || continue
     base_name=$(basename "$sh_file" .sh)
     conf_file="./staging/${base_name}.conf"
     if [ -f "$conf_file" ]; then
-        parent=$(grep '^parent=' "$conf_file" | head -n1 | cut -d= -f2- | xargs)
+        local parent
+        parent=$(grep '^parent=' "$conf_file" | head -n1 | cut -d= -f2- | xargs)
         if [ -n "$parent" ]; then
             dest_dir="./src/$parent"
             mkdir -p "$dest_dir"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4db54c2 and 3b9744f.

📒 Files selected for processing (2)
  • tools/00_setup_module.sh (1 hunks)
  • tools/04_promote_module.sh (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tools/00_setup_module.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
tools/04_promote_module.sh

[warning] 9-9: array_entries appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 10-10: group_counts appears unused. Verify use (or export if used externally).

(SC2034)

@Tearran Tearran merged commit 9c07d63 into main Jun 18, 2025
4 of 5 checks passed
@Tearran Tearran deleted the helper_registry branch June 18, 2025 05:11
This was referenced Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants