Skip to content

Commit 282723e

Browse files
committed
Rearrange Code in UpdateCommand
1 parent 942ea16 commit 282723e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

app/Commands/UpdateCommand.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class UpdateCommand extends Command
1515
protected $signature = 'update
1616
{--release-notes= : Markdown Release Notes to be added to the CHANGELOG}
1717
{--latest-version= : The version the CHANGELOG should be updated too}
18-
{--release-date= : Date when latest version has been released}
18+
{--release-date= : Date when latest version has been released. Defaults to today.}
1919
{--path-to-changelog=CHANGELOG.md : Path to changelog markdown file to be updated}
2020
{-w\--write : Write changes to file}
2121
';
@@ -33,7 +33,6 @@ public function handle(AddReleaseNotesToChangelog $addReleaseNotesToChangelog):
3333
$latestVersion = $this->option('latest-version');
3434
$releaseDate = $this->option('release-date');
3535
$pathToChangelog = $this->option('path-to-changelog');
36-
$shouldWriteToFile = $this->option('write');
3736

3837
if (empty($releaseDate)) {
3938
$releaseDate = now()->format('Y-m-d');
@@ -50,24 +49,24 @@ public function handle(AddReleaseNotesToChangelog $addReleaseNotesToChangelog):
5049

5150
$this->info($updatedChangelog->getContent());
5251

53-
$this->writeChangelogToFile($shouldWriteToFile, $pathToChangelog, $updatedChangelog);
52+
$this->writeChangelogToFile($pathToChangelog, $updatedChangelog);
53+
}
54+
55+
private function validateOptions(): void
56+
{
57+
Assert::stringNotEmpty($this->option('release-notes'), 'No release-notes option provided. Abort.');
58+
Assert::stringNotEmpty($this->option('latest-version'), 'No latest-version option provided. Abort.');
5459
}
5560

5661
protected function getChangelogContent(string $pathToChangelog): bool | string
5762
{
5863
return file_get_contents($pathToChangelog);
5964
}
6065

61-
protected function writeChangelogToFile(bool $shouldWriteToFile, string $pathToChangelog, RenderedContentInterface $updatedMarkdown): void
66+
protected function writeChangelogToFile(string $pathToChangelog, RenderedContentInterface $updatedMarkdown): void
6267
{
63-
if ($shouldWriteToFile) {
68+
if ($this->option('write')) {
6469
file_put_contents($pathToChangelog, $updatedMarkdown->getContent());
6570
}
6671
}
67-
68-
private function validateOptions(): void
69-
{
70-
Assert::stringNotEmpty($this->option('release-notes'), 'No release-notes option provided. Abort.');
71-
Assert::stringNotEmpty($this->option('latest-version'), 'No latest-version option provided. Abort.');
72-
}
7372
}

0 commit comments

Comments
 (0)