From e94fdbf837af3fd67fc353cc7cf2ba0f76d61ee3 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Wed, 2 Jul 2025 20:55:05 +0200 Subject: [PATCH] feat(bash): add self-contained help extraction script - Introduces a Bash script showcasing embedded help text extraction - Implements a `show_help` function utilizing `sed` for parsing comments - Supports `--help` and `--verbose` options for enhanced usability --- snippets/bash/show_help.sh | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 snippets/bash/show_help.sh diff --git a/snippets/bash/show_help.sh b/snippets/bash/show_help.sh new file mode 100644 index 0000000..75d99e6 --- /dev/null +++ b/snippets/bash/show_help.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# show_help.sh – Example Bash script with embedded help section +# SPDX-License-Identifier: MIT + +# Use this snippet as a pattern for Bash scripts that include their own help text +# inside comment blocks. The `show_help` function will extract the lines between +# `#=== HELP START ===` and `#=== HELP END ===`, strip the leading `#` and output +# a clean help message. + +# ───────────────────────────────────────────────────────────── + +show_help() { + sed -n '/^#=== HELP START ===/,/^#=== HELP END ===/ { + /^#=== HELP START ===/d + /^#=== HELP END ===/d + s/^# *// + p + }' "$0" +} + +# --- Example usage of the show_help function --- + +#=== HELP START === +# Example Script +# +# Usage: +# ./show_help.sh [options] +# +# Options: +# -h, --help Show this help message and exit +# -v, --verbose Enable verbose output +# +# Description: +# This is an example of how to embed a self-contained help +# section in a Bash script using a simple sed-based extractor. +#=== HELP END === + +# ───────────────────────────────────────────────────────────── + +# Main entrypoint +case "$1" in + -h|--help) + show_help + exit 0 + ;; + -v|--verbose) + echo "Verbose mode enabled" + ;; + *) + echo "Run with --help for usage." + ;; +esac