Skip to content

Commit

Permalink
Remove CLI description parameter from GenFormula
Browse files Browse the repository at this point in the history
Refactor GenFormula invocation by eliminating the redundant CLI description parameter. The description now defaults to the meta name, simplifying both the function signature and its usage. Updated corresponding test cases and script logic to reflect this change.
  • Loading branch information
koriym committed Nov 14, 2024
1 parent a1135c1 commit f2790b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 1 addition & 5 deletions src/CompileScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __construct(
public function compile(Meta $meta): array
{
$sources = [];
$cliDesc = '';
$generator = $meta->getGenerator();

foreach ($generator as $resource) {
Expand All @@ -46,9 +45,6 @@ public function compile(Meta $meta): array
continue;
}

// Get CLI description for formula
$cliDesc = $cliAttr->description;

$sources[] = ($this->genScript)(
uri: $resource->uriPath,
appDir: $meta->appDir,
Expand All @@ -60,7 +56,7 @@ public function compile(Meta $meta): array
// Generate formula if it's a git repository
$formula = null;
if (is_dir($meta->appDir . '/.git')) {
$formula = ($this->genFormula)($meta, $cliDesc);
$formula = ($this->genFormula)($meta);
}

$this->dumpSources($sources, $meta->appDir . '/bin/cli');
Expand Down
6 changes: 3 additions & 3 deletions src/GenFormula.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class GenFormula
# frozen_string_literal: true
class %s < Formula
desc "%s"
desc "Command line interface for %s application"
homepage "%s"
head "%s", branch: "%s"
license "MIT"
Expand Down Expand Up @@ -100,7 +100,7 @@ private function generateFormulaName(string $repoName): string
}

/** @return Formula */
public function __invoke(Meta $meta, string $description): array
public function __invoke(Meta $meta): array
{
$repoUrl = $this->gitCommand->getRemoteUrl();

Expand All @@ -115,7 +115,7 @@ public function __invoke(Meta $meta, string $description): array
$content = sprintf(
self::TEMPLATE,
ucfirst($formulaName),
$description,
$meta->name,
"https://github.com/{$repoInfo['org']}/{$repoInfo['repo']}",
$repoUrl,
$branch,
Expand Down
10 changes: 5 additions & 5 deletions tests/GenFormulaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function detectMainBranch(string $repoUrl): string
}
};
$genFormula = new GenFormula($gitCommand);
$result = $genFormula($this->meta, 'Test CLI command');
$result = $genFormula($this->meta);

// Check formula path
$expectedPath = sprintf(
Expand All @@ -68,7 +68,7 @@ public function detectMainBranch(string $repoUrl): string
// Check formula content
$content = $result['content'];
$this->assertStringContainsString('class Fakeproject < Formula', $content);
$this->assertStringContainsString('desc "Test CLI command"', $content);
$this->assertStringContainsString('desc "Command line interface for FakeVendor\FakeProject application"', $content);
$this->assertStringContainsString('homepage "https://github.com/fakevendor/fake-project"', $content);
$this->assertStringContainsString('head "https://github.com/fakevendor/fake-project.git"', $content);
$this->assertStringContainsString('depends_on "php@', $content);
Expand All @@ -95,7 +95,7 @@ public function detectMainBranch(string $repoUrl): string
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Invalid GitHub URL format');

$genFormula($this->meta, 'Test CLI command');
$genFormula($this->meta);
}

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ public function detectMainBranch(string $repoUrl): string
};
$genFormula = new GenFormula($gitCommand);

$result = $genFormula($this->meta, 'Test CLI command');
$result = $genFormula($this->meta);

$this->assertStringContainsString(
sprintf('class %s < Formula', ucfirst($expectedFormulaName)),
Expand Down Expand Up @@ -160,7 +160,7 @@ public function detectMainBranch(string $repoUrl): string
};
$genFormula = new GenFormula($gitCommand);

$result = $genFormula($this->meta, 'Test CLI command');
$result = $genFormula($this->meta);

$this->assertStringContainsString(
'homepage "https://github.com/fakevendor/fake-project"',
Expand Down

0 comments on commit f2790b1

Please sign in to comment.