File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # doc.sh
2+
3+ ## Purpose
4+ Generate quick-reference documentation for the shared lock module.
5+
6+ ## Location
7+ ` shared/lock/doc.sh `
8+
9+ ## Preconditions
10+ - Required tools: ` bash `
11+ - Required permissions: write permission when using ` --output `
12+ - Required environment variables: none
13+
14+ ## Arguments
15+ | Flag | Required | Default | Description |
16+ | ------| ----------| ---------| -------------|
17+ | ` --format FORMAT ` | No | ` markdown ` | Output format: ` markdown ` or ` text ` |
18+ | ` --output PATH ` | No | stdout | Write rendered content to file |
19+
20+ ## Usage
21+ ``` bash
22+ shared/lock/doc.sh
23+ shared/lock/doc.sh --format text --output /tmp/lock-doc.txt
24+ ```
25+
26+ ## Output
27+ - Exit codes: ` 0 ` success, ` 2 ` invalid args.
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ usage () {
5+ cat << 'USAGE '
6+ Usage: doc.sh [OPTIONS]
7+
8+ Generate quick reference docs for the lock shared module.
9+
10+ Options:
11+ --format FORMAT markdown|text (default: markdown)
12+ --output PATH Write to file instead of stdout
13+ -h, --help Show help
14+ USAGE
15+ }
16+
17+ die () {
18+ printf ' ERROR: %s\n' " $* " >&2
19+ exit 2
20+ }
21+
22+ format=" markdown"
23+ output=" "
24+
25+ while (( $# )) ; do
26+ case " $1 " in
27+ --format)
28+ shift
29+ (( $# )) || die " --format requires a value"
30+ format=" $1 "
31+ ;;
32+ --output)
33+ shift
34+ (( $# )) || die " --output requires a value"
35+ output=" $1 "
36+ ;;
37+ -h|--help)
38+ usage
39+ exit 0
40+ ;;
41+ * )
42+ die " unknown option: $1 "
43+ ;;
44+ esac
45+ shift
46+ done
47+
48+ render_markdown () {
49+ cat << 'MD '
50+ # shared/lock Module
51+
52+ ## Scripts
53+ - `shared/lock/example.sh`: wraps `shared/safety/file-lock.sh` with example defaults
54+ - `shared/lock/test.sh`: validates lock acquisition, contention timeout, and stale lock cleanup
55+ - `shared/lock/doc.sh`: generates this quick reference
56+
57+ ## Core Dependencies
58+ - `shared/safety/file-lock.sh`
59+ MD
60+ }
61+
62+ render_text () {
63+ cat << 'TXT '
64+ shared/lock module
65+
66+ scripts:
67+ - shared/lock/example.sh: lock wrapper example
68+ - shared/lock/test.sh: smoke tests for lock behavior
69+ - shared/lock/doc.sh: quick reference generator
70+
71+ dependencies:
72+ - shared/safety/file-lock.sh
73+ TXT
74+ }
75+
76+ case " $format " in
77+ markdown)
78+ rendered=" $( render_markdown) "
79+ ;;
80+ text)
81+ rendered=" $( render_text) "
82+ ;;
83+ * )
84+ die " invalid --format: $format "
85+ ;;
86+ esac
87+
88+ if [[ -n " $output " ]]; then
89+ printf ' %s\n' " $rendered " > " $output "
90+ else
91+ printf ' %s\n' " $rendered "
92+ fi
You can’t perform that action at this time.
0 commit comments