Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ _Output_: [examples/readme-example.md](examples/readme-example.md)<br/><br/>
#
# @requires foo
# @requires bar
# @deprecated use yell-hello instead
#
# @see validate()
# @see [shdoc](https://github.com/reconquest/shdoc).
Expand Down Expand Up @@ -104,6 +105,10 @@ deeper-level() { echo; }

# @description Back up again
up-again() { echo; }

# @description A deprecated function
# @deprecated Because it's old
deprecated-function() { echo; }
~~~

</td>
Expand All @@ -128,9 +133,12 @@ The project solves lots of problems:
* [Sub-section](#sub-section)
* [deeper-level](#deeper-level)
* [up-again](#up-again)
* [deprecated-function](#deprecated-function)

## say-hello

**DEPRECATED** Use yell-hello instead

My super function.
Not thread-safe.

Expand Down Expand Up @@ -199,6 +207,11 @@ This is nested

Back up again

## deprecated-function

**DEPRECATED** Because it's old

A deprecated function
~~~

</td>
Expand Down Expand Up @@ -258,6 +271,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. Creates a paragraph titled with the section name.
Expand Down Expand Up @@ -392,6 +418,19 @@ set-hello() {
}
```

### `@deprecated`

Indicates that the function is deprecated

**Example**

```bash
# @deprecated use yell-hello-world instead
say-hello-world() {
...
}
```

### `@exitcode`

Describes an expected exitcode of the function.
Expand Down
17 changes: 12 additions & 5 deletions examples/readme-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The project solves lots of problems:
* [Sub-section](#sub-section)
* [deeper-level](#deeper-level)
* [up-again](#up-again)
* [deprecated-function](#deprecated-function)

## say-hello

Expand Down Expand Up @@ -62,17 +63,17 @@ echo "test: $(say-hello World)"
* Output 'Oups !' on error.
It did it again.

### See also

* [validate()](#validate)
* [shdoc](https://github.com/reconquest/shdoc).

### Requires

* Some very specific requirements
that continue on the next line (indent by a
single space to continue)

### See also

* [validate()](#validate)
* [shdoc](https://github.com/reconquest/shdoc).

## Sub-section

Some grouped functions.
Expand All @@ -98,3 +99,9 @@ This is nested

Back up again

## deprecated-function

**DEPRECATED** Because it's old

A deprecated function

4 changes: 4 additions & 0 deletions examples/readme-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ deeper-level() { echo; }

# @description Back up again
up-again() { echo; }

# @description A deprecated function
# @deprecated Because it's old
deprecated-function() { echo; }
21 changes: 19 additions & 2 deletions shdoc
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,14 @@ function render_docblock(func_name, description, docblock, nesting) {
lines[0] = render(nesting_top, func_name)
}

if (deprecated) {
debug("→ DEPRECATED")

deprecatedText = render("strong", "DEPRECATED")
push(lines, deprecatedText " " deprecated)
push(lines, "")
}

if (description != "") {
push(lines, description)
# Add empty line to signal end of description.
Expand Down Expand Up @@ -725,11 +733,12 @@ function debug(msg) {

handle_description()

sub(/@description/, "")
reset()
}

in_description {
if (/^[^[[:space:]]*#]|^[[:space:]]*# @[^d]|^[[:space:]]*[^#]|^[[:space:]]*$/) {
if (/^[^[[:space:]]*#]|^[[:space:]]*# @[a-z]+|^[[:space:]]*[^#]|^[[:space:]]*$/) {
debug("→ → in_description: leave")

in_description = 0
Expand All @@ -741,7 +750,6 @@ in_description {
description = concat(description, $0)
next
} else {
sub(/^[[:space:]]*# @description[[:space:]]*/, "")
sub(/^[[:space:]]*#[[:space:]]*/, "")
sub(/^[[:space:]]*#$/, "")
debug("→ → in_description: concat [" $0 "]")
Expand Down Expand Up @@ -892,6 +900,15 @@ in_example {
next
}

/^[[:space:]]*# @deprecated/ {
debug("→ @deprecated")
sub(/[[:space:]]*# @deprecated /, "")

deprecated = $0

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.
Expand Down
25 changes: 25 additions & 0 deletions tests/testcases/@deprecated.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

tests:put input <<EOF
# @description FUNCTION DESCRIPTION
#
# @deprecated this one is ignored
# @deprecated REASON
# ignored line
func() {

EOF

tests:put expected <<EOF
## Index

* [func](#func)

## func

**DEPRECATED** REASON

FUNCTION DESCRIPTION
EOF

assert