Skip to content

scripts: streamline argument parsing and help usage for scripts#7

Merged
bybatkhuu merged 2 commits intomainfrom
dev
Nov 4, 2025
Merged

scripts: streamline argument parsing and help usage for scripts#7
bybatkhuu merged 2 commits intomainfrom
dev

Conversation

@bybatkhuu
Copy link
Copy Markdown
Contributor

This pull request refactors the argument parsing and help output for several shell scripts, improving usability and consistency. The main changes include replacing custom argument parsing logic with a standardized approach, adding detailed usage/help messages, and cleaning up script entry points.

Argument parsing and help improvements:

  • Standardized argument parsing using while [ $# -gt 0 ]; do ... and added comprehensive _usage_help functions to scripts/bump-version.sh, scripts/changelog.sh, scripts/clean.sh, and scripts/docs.sh. This provides clear usage instructions, options, and examples for each script. [1] [2] [3] [4]
  • Improved error handling for invalid or missing arguments, now showing the usage help message on error for all scripts. [1] [2] [3] [4]

Validation and main function cleanup:

  • Added argument validation steps (e.g., checking required tools like git when needed) and moved them outside the main logic for better separation and readability. [1] [2] [3]
  • Refactored script entry points to call main without passing arguments, since argument parsing is now handled before the main function. [1] [2] [3] [4] [5]

Minor cleanup:

  • Removed redundant checks and legacy code related to argument parsing, simplifying script structure. [1] [2] [3] [4]

These changes make the scripts easier to use, maintain, and extend, with consistent behavior across the tooling.

@bybatkhuu bybatkhuu self-assigned this Nov 4, 2025
Copilot AI review requested due to automatic review settings November 4, 2025 06:33
Copy link
Copy Markdown

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 PR refactors argument parsing across shell scripts by moving argument handling from inside the main() function to the top-level script scope, and enhances user experience with help documentation.

Key changes:

  • Moved argument parsing from inside main() to top-level script scope using while [ $# -gt 0 ] loops
  • Added _usage_help() functions with formatted help documentation and examples
  • Separated argument validation logic into dedicated sections with clear comment markers
  • Removed arguments from main function calls (changed from main "${@:-}" to main)

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/release.sh Removed arguments from main function call (no argument parsing in this script)
scripts/docs.sh Refactored argument parsing to top-level, added help function with examples, separated validation logic
scripts/clean.sh Refactored argument parsing to top-level, added help function with examples
scripts/changelog.sh Refactored argument parsing to top-level, added help function with examples, separated validation logic
scripts/bump-version.sh Refactored argument parsing to top-level, added help function with examples, separated validation logic, added support for space-separated argument values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

while [ $# -gt 0 ]; do
case "${1}" in
-b | --bump | --bump-type)
[ $# -ge 2 ] || { echo "[ERROR]: ${1} requires a value!" >&2; exit 1; }
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The argument parsing for -b | --bump | --bump-type now accepts space-separated values, but the error message at line 79 still instructs users to use the equals sign format (-b= or --bump-type=). Update the error message to reflect that both formats are now supported (e.g., -b patch or --bump-type=patch).

Suggested change
[ $# -ge 2 ] || { echo "[ERROR]: ${1} requires a value!" >&2; exit 1; }
[ $# -ge 2 ] || { echo "[ERROR]: ${1} requires a value! Usage: -b patch or --bump-type=patch" >&2; exit 1; }

Copilot uses AI. Check for mistakes.
[ $# -ge 2 ] || { echo "[ERROR]: ${1} requires a value!" >&2; exit 1; }
_BUMP_TYPE="${2}"
shift 2;;
-b=* | --bump=* | --bump-type=*)
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The --bump=* pattern is not documented in the help text at line 35. Either add --bump to the OPTIONS documentation or remove this case pattern to keep the implementation consistent with the documented interface.

Copilot uses AI. Check for mistakes.
@bybatkhuu bybatkhuu merged commit 1dfe227 into main Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants