Skip to content
Draft
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
32 changes: 32 additions & 0 deletions app/Commands/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ private function getSourceFile(ConfigService $configService): ?string
$localExists = File::exists($localRulesFile);
$globalExists = File::exists($globalRulesFile);

if (! $localExists && ! $globalExists) {
return $this->handleMissingSourceFile($configService);
}

if (! $globalExists && $configService->getWarnOnMissingGlobalRules()) {
$this->line('');
$this->warn('No global rulesync.md file found at ~/.config/rulesync/rulesync.md');

if ($this->confirm('Do you want to hide this warning in the future?')) {
$configService->setWarnOnMissingGlobalRules(false);
}
}

if (! $localExists && $configService->getWarnOnMissingLocalRules()) {
$this->line('');
$this->warn('No local rulesync.md file found in the current directory.');

if ($this->confirm('Do you want to hide this warning in the future?')) {
$configService->setWarnOnMissingLocalRules(false);
}
}

// If both local and global files exist, handle augmentation
if ($localExists && $globalExists && $localRulesFile !== $globalRulesFile) {
return $this->handleAugmentation($configService, $localRulesFile, $globalRulesFile);
Expand All @@ -112,6 +134,7 @@ private function getSourceFile(ConfigService $configService): ?string
return $globalRulesFile;
}

// This part should not be reachable if the logic is correct, but as a fallback:
return $this->handleMissingSourceFile($configService);
}

Expand Down Expand Up @@ -235,6 +258,15 @@ private function isUnderVersionControl(): bool

private function handleMissingSourceFile(ConfigService $configService): ?string
{
if ($configService->getWarnOnMissingRules()) {
$this->line('');
$this->warn('No rulesync.md file found globally or locally.');

if ($this->confirm('Do you want to hide this warning in the future?')) {
$configService->setWarnOnMissingRules(false);
}
}

$this->error('No source file found.');

$existingRuleFiles = $this->findExistingRuleFiles();
Expand Down
33 changes: 33 additions & 0 deletions app/Services/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,39 @@ public function setAugmentPreference(bool $augment): void
$this->saveConfig();
}

public function getWarnOnMissingGlobalRules(): bool
{
return $this->config['warn_on_missing_global_rules'] ?? true;
}

public function setWarnOnMissingGlobalRules(bool $warn): void
{
$this->config['warn_on_missing_global_rules'] = $warn;
$this->saveConfig();
}

public function getWarnOnMissingLocalRules(): bool
{
return $this->config['warn_on_missing_local_rules'] ?? true;
}

public function setWarnOnMissingLocalRules(bool $warn): void
{
$this->config['warn_on_missing_local_rules'] = $warn;
$this->saveConfig();
}

public function getWarnOnMissingRules(): bool
{
return $this->config['warn_on_missing_rules'] ?? true;
}

public function setWarnOnMissingRules(bool $warn): void
{
$this->config['warn_on_missing_rules'] = $warn;
$this->saveConfig();
}

private function ensureConfigDirectoryExists(): void
{
$directory = dirname($this->configPath);
Expand Down
59 changes: 58 additions & 1 deletion tests/Feature/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function test_fails_when_no_source_file(): void
File::ensureDirectoryExists($this->tempDir.'/.git');
File::put($this->tempDir.'/.git/config', '');

$this->artisan('generate --force')
$this->artisan('generate')
->expectsOutput('No rulesync.md file found globally or locally.')
->expectsQuestion('Do you want to hide this warning in the future?', false)
->expectsOutputToContain('No source file found.')
->assertExitCode(1);
}
Expand Down Expand Up @@ -105,4 +107,59 @@ public function test_basic_generation_works(): void
->expectsOutputToContain('Generation complete:')
->assertExitCode(0);
}

public function test_hides_missing_global_rules_warning_when_confirmed(): void
{
File::put($this->tempDir.'/rulesync.md', '# My Rules');
File::ensureDirectoryExists($this->tempDir.'/.git');
File::put($this->tempDir.'/.git/config', '');

// First run: expect warning and confirm to hide it
$this->artisan('generate')
->expectsOutput('No global rulesync.md file found at ~/.config/rulesync/rulesync.md')
->expectsQuestion('Do you want to hide this warning in the future?', true)
->assertExitCode(0);

// Second run: expect no warning
$this->artisan('generate')
->doesntExpectOutput('No global rulesync.md file found at ~/.config/rulesync/rulesync.md')
->assertExitCode(0);
}

public function test_hides_missing_local_rules_warning_when_confirmed(): void
{
$globalConfigDir = $this->tempDir.'/.config/rulesync';
File::ensureDirectoryExists($globalConfigDir);
File::put($globalConfigDir.'/rulesync.md', '# Global Rules');
File::ensureDirectoryExists($this->tempDir.'/.git');
File::put($this->tempDir.'/.git/config', '');

// First run: expect warning and confirm to hide it
$this->artisan('generate')
->expectsOutput('No local rulesync.md file found in the current directory.')
->expectsQuestion('Do you want to hide this warning in the future?', true)
->assertExitCode(0);

// Second run: expect no warning
$this->artisan('generate')
->doesntExpectOutput('No local rulesync.md file found in the current directory.')
->assertExitCode(0);
}

public function test_hides_missing_rules_warning_when_confirmed(): void
{
File::ensureDirectoryExists($this->tempDir.'/.git');
File::put($this->tempDir.'/.git/config', '');

// First run: expect warning and confirm to hide it
$this->artisan('generate')
->expectsOutput('No rulesync.md file found globally or locally.')
->expectsQuestion('Do you want to hide this warning in the future?', true)
->assertExitCode(1);

// Second run: expect no warning
$this->artisan('generate')
->doesntExpectOutput('No rulesync.md file found globally or locally.')
->assertExitCode(1);
}
}
26 changes: 26 additions & 0 deletions tests/Unit/Services/ConfigServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ public function test_returns_null_augment_preference_when_not_set(): void
expect($this->configService->getAugmentPreference())->toBeNull();
}

public function test_can_set_warning_preferences(): void
{
// Test defaults
expect($this->configService->getWarnOnMissingGlobalRules())->toBeTrue();
expect($this->configService->getWarnOnMissingLocalRules())->toBeTrue();
expect($this->configService->getWarnOnMissingRules())->toBeTrue();

// Test setting to false
$this->configService->setWarnOnMissingGlobalRules(false);
$this->configService->setWarnOnMissingLocalRules(false);
$this->configService->setWarnOnMissingRules(false);

expect($this->configService->getWarnOnMissingGlobalRules())->toBeFalse();
expect($this->configService->getWarnOnMissingLocalRules())->toBeFalse();
expect($this->configService->getWarnOnMissingRules())->toBeFalse();

// Test setting back to true
$this->configService->setWarnOnMissingGlobalRules(true);
$this->configService->setWarnOnMissingLocalRules(true);
$this->configService->setWarnOnMissingRules(true);

expect($this->configService->getWarnOnMissingGlobalRules())->toBeTrue();
expect($this->configService->getWarnOnMissingLocalRules())->toBeTrue();
expect($this->configService->getWarnOnMissingRules())->toBeTrue();
}

public function test_persists_config_to_file(): void
{
$this->configService->disableRule('claude');
Expand Down
Loading