diff --git a/README.md b/README.md index 5b9bc48..fd020e1 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,19 @@ function super() { } ``` +### `@deprecated` + +Whether or not the function is deprecated. If it is, a short deprecation notice +will be prepended to the description. + +**Example** +```bash +# @deprecated +say-hello() { + ... +} +``` + ### `@section` The name of a section of the file. Can be used to group functions. diff --git a/shdoc b/shdoc index 5fbdad3..ac758bf 100755 --- a/shdoc +++ b/shdoc @@ -473,6 +473,17 @@ function render_docblock(func_name, description, docblock) { lines[0] = render("h3", func_name) } + if ("deprecated" in docblock) { + debug("→ DEPRECATED") + + deprecatedText = "**DEPRECATED.**" + if (description != "") { + description = deprecatedText " " description + } else { + push(lines, deprecatedText) + } + } + if (description != "") { push(lines, description) # Add empty line to signal end of description. @@ -639,7 +650,7 @@ function debug(msg) { } in_description { - if (/^[^[[:space:]]*#]|^[[:space:]]*# @[^d]|^[[:space:]]*[^#]|^[[:space:]]*$/) { + if (/^[^[[:space:]]*#]|^[[:space:]]*# @[a-z]+|^[[:space:]]*[^#]|^[[:space:]]*$/ && !match($0, /@description/)) { debug("→ → in_description: leave") in_description = 0 @@ -783,6 +794,15 @@ in_example { next } +/^[[:space:]]*# @deprecated/ { + debug("→ @deprecated") + sub(/[[:space:]]*# @deprecated /, "") + + docblock_push("deprecated", "") + + next +} + # Previous line added a new docblock item. # Check if current line has the needed indentation # for it to be a multiple lines docblock item. diff --git a/tests/testcases/@deprecated-standalone.test.sh b/tests/testcases/@deprecated-standalone.test.sh new file mode 100644 index 0000000..009e87b --- /dev/null +++ b/tests/testcases/@deprecated-standalone.test.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +tests:put input <