Skip to content

Commit

Permalink
Added support for a --skip-text option.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 26, 2023
1 parent ef66072 commit 5c6d12c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ like so: `--exclude-prefix=VAR1 --exclude-prefix=VAR2` etc.
| Name | Description | Default value |
|------------------------------------|--------------------------------------------------------------------------------------|---------------|
| `paths` | File or directory to scan. Multiple files separated by space. | |
| `--skip-text=SKIP` | Skip variable extraction if the comment has this specified text. | `@skip` |
| `--skip-description-prefix=PREFIX` | Skip description lines that start with the provided prefix. Multiple values allowed. | |

### Filtering
Expand Down
7 changes: 7 additions & 0 deletions src/Extractor/AbstractExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public static function getConsoleArguments(): array {
*/
public static function getConsoleOptions(): array {
return [
new InputOption(
name: 'skip-text',
mode: InputOption::VALUE_REQUIRED,
description: 'Skip variable extraction if the comment has this specified text.',
default: '@skip'
),
new InputOption(
name: 'skip-description-prefix',
mode: InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
Expand All @@ -62,6 +68,7 @@ public static function getConsoleOptions(): array {
*/
protected function processConfig(Config $config): void {
$config->set('paths', $this->scanPaths(Utils::resolvePaths($config->get('paths', []))));
$config->set('skip-text', $config->get('skip-text', '@skip'));
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Extractor/ShellExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function extract(): array {
* {@inheritdoc}
*/
protected function extractVariablesFromFile($file): void {
$skip = $this->config->get('skip-text');
$lines = Utils::getLinesFromFiles([$file]);

foreach ($lines as $num => $line) {
Expand All @@ -64,6 +65,10 @@ protected function extractVariablesFromFile($file): void {

$description = $this->extractVariableDescription($lines, $num, $this->config->get('skip-description-prefix'));
if ($description) {
if ($skip && str_contains($description, $skip)) {
continue;
}

$var->setDescription($description);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Fixtures/test-data-skip-text.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
##
# Test data file for variables extraction script.
#
# shellcheck disable=SC2034,SC2154

# @skip
VAR1=val1

# Description from bash without a leading space that goes on
# multiple lines.
# @docs-skip
VAR2=val2

37 changes: 37 additions & 0 deletions tests/Functional/MarkdownBlocksFormatterFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,43 @@ public function dataProviderFormatter() {
EOD,
],

// Skip - default.
[
[
'--exclude-local',
'--sort',
'--format=md-blocks',
$this->fixtureFile('test-data-skip-text.sh'),
],
<<<'EOD'
### `VAR2`
Description from bash without a leading space that goes on<br />multiple lines.<br />@docs-skip
Default value: `val2`
EOD,
],

// Skip - custom.
[
[
'--exclude-local',
'--sort',
'--format=md-blocks',
'--skip-text=docs-skip',
$this->fixtureFile('test-data-skip-text.sh'),
],
<<<'EOD'
### `VAR1`
@skip
Default value: `val1`
EOD,
],
];
}

Expand Down

0 comments on commit 5c6d12c

Please sign in to comment.