Skip to content
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bf31e7e
feat: add `create` command
grandeljay Nov 5, 2023
693b496
feat: add `archiveName` interaction
grandeljay Nov 6, 2023
e496d39
chore: merge `feat/mmlc-cli` into `create`
grandeljay Nov 6, 2023
69a029b
fix: refactor to match newest upstream changes
grandeljay Nov 6, 2023
a3b796d
fix: missing arguments
grandeljay Nov 6, 2023
badc16a
chore: merge `feat/mmlc-cli` into `create`
grandeljay Nov 7, 2023
d6d5d58
refactor: add `HelpRenderer`
grandeljay Nov 7, 2023
8a562e7
refactor: fix indentation
grandeljay Nov 7, 2023
8f87634
chore: merge `feat/mmlc-cli` into `create`
grandeljay Nov 14, 2023
80a5786
refactor: add specialised methods, rename `getPadding`
grandeljay Nov 14, 2023
3ae50ce
fix: remove duplicate command
grandeljay Nov 14, 2023
6f44386
refactor: remove unused method `renderLogo`
grandeljay Nov 14, 2023
208e135
fix: re-add required render methods
grandeljay Nov 14, 2023
118a28f
feat: automatically pad options and description
grandeljay Nov 14, 2023
d76011c
refactor: rename property `arguments` to `sections`
grandeljay Nov 14, 2023
42be461
refactor: simply code
grandeljay Nov 15, 2023
38a7d1e
feat: improve `HelpRenderer`
grandeljay Nov 15, 2023
d7c3ac7
refactor: remove unused method `leftPad`
grandeljay Nov 15, 2023
1d3e3c7
refactor: remove test option
grandeljay Nov 15, 2023
ff06fcd
refactor: let caller print new lines
grandeljay Nov 15, 2023
e4c0a99
Merge `feat/mmlc-cli` into `create`
grandeljay Nov 15, 2023
7b12d1e
chore: merge `feat/mmlc-cli` into `create`
grandeljay Nov 15, 2023
63f0497
refactor: move `rightPad` back where it was
grandeljay Nov 15, 2023
1efe045
feat: add create command
grandeljay Jan 9, 2024
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
72 changes: 43 additions & 29 deletions src/Classes/Cli/HelpRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,14 @@ public function addArgument(string $argument, string $description): void

public function addOption(string $short, string $long, string $description): void
{
$option = $short . $long;
$formatted = '';

if ($short && $long) {
$formatted = "-$short, --$long";
} elseif ($short) {
$formatted = "-$short";
} elseif ($long) {
$formatted = " --$long";
}

$this->sections['options'][$option] = [
'short' => $short,
'long' => $long,
'formatted' => $formatted,
$option = [
'short' => TextRenderer::color($short ? '-' . $short : '', TextRenderer::COLOR_GREEN),
'separator' => TextRenderer::color($short && $long ? ', ' : '', TextRenderer::COLOR_GREEN),
'long' => TextRenderer::color($long ? '--' . $long : '', TextRenderer::COLOR_GREEN),
'description' => $description,
];

$this->sections['options'][] = $option;
}
Comment thread
grandeljay marked this conversation as resolved.

public function render(): string
Expand Down Expand Up @@ -126,24 +117,47 @@ private function renderOptions(): string
return '';
}

$arguments = \PHP_EOL;
$arguments .= TextRenderer::color('Options:', TextRenderer::COLOR_YELLOW) . \PHP_EOL;
$options = \PHP_EOL;
Comment thread
grandeljay marked this conversation as resolved.
Outdated
$options .= TextRenderer::color('Options:', TextRenderer::COLOR_YELLOW) . \PHP_EOL;

$optionsFormatted = \array_map(
function ($option) {
return $option['formatted'];
},
$this->sections['options']
);
$optionsPadding = TextRenderer::getMaxLength($optionsFormatted) + 1;
$optionsShort = self::getTableColumn($this->sections['options'], 'short');
$optionsShortLength = TextRenderer::getMaxLength($optionsShort);

foreach ($this->sections['options'] as $option) {
$name = TextRenderer::rightPad($option['formatted'], $optionsPadding);
$text = self::INDENT . TextRenderer::color($name, TextRenderer::COLOR_GREEN) . $option['description'] . \PHP_EOL;
$optionsSeparator = self::getTableColumn($this->sections['options'], 'separator');
$optionsSeparatorLength = TextRenderer::getMaxLength($optionsSeparator);

$arguments .= $text;
$optionsLong = self::getTableColumn($this->sections['options'], 'long');
$optionsLongLength = TextRenderer::getMaxLength($optionsLong);

$optionsDescription = self::getTableColumn($this->sections['options'], 'description');
$optionsDescriptionLength = TextRenderer::getMaxLength($optionsDescription);

foreach ($this->sections['options'] as $option) {
$short = $option['short'];
$separator = $option['separator'];
$long = $option['long'];
$description = $option['description'];

$options .= self::INDENT;
$options .= TextRenderer::rightPad($short, $optionsShortLength);
$options .= TextRenderer::rightPad($separator, $optionsSeparatorLength);
$options .= TextRenderer::rightPad($long, $optionsLongLength);
$options .= ' ';
$options .= TextRenderer::rightPad($description, $optionsDescriptionLength);
$options .= \PHP_EOL;
}

return $arguments;
return $options;
}

private static function getTableColumn(array $table, string $column): array {
$tableColumn = \array_map(
function ($row) use ($column) {
return $row[$column];
},
$table
);

return $tableColumn;
}
}