Skip to content

Commit 3207793

Browse files
committed
feat: add TUI command for browsing dependency changes
1 parent bd3bf72 commit 3207793

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

src/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Symfony\Component\Console\Application as BaseApplication;
88
use Whatsdiff\Commands\DiffCommand;
9+
use Whatsdiff\Commands\TuiCommand;
910

1011
class Application extends BaseApplication
1112
{
@@ -30,7 +31,8 @@ public function __construct()
3031
parent::__construct('whatsdiff', $versionString);
3132

3233
$this->add(new DiffCommand());
33-
$this->setDefaultCommand('diff', true);
34+
$this->add(new TuiCommand());
35+
$this->setDefaultCommand('diff');
3436
}
3537

3638
public function getLongVersion(): string

src/Commands/TuiCommand.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Whatsdiff\Commands;
6+
7+
use Symfony\Component\Console\Attribute\AsCommand;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
use Whatsdiff\Outputs\Tui\TerminalUI;
13+
use Whatsdiff\Services\DiffCalculator;
14+
use Whatsdiff\Services\GitRepository;
15+
use Whatsdiff\Services\ComposerAnalyzer;
16+
use Whatsdiff\Services\NpmAnalyzer;
17+
use Whatsdiff\Services\PackageInfoFetcher;
18+
19+
#[AsCommand(
20+
name: 'tui',
21+
description: 'Launch the Terminal User Interface to browse dependency changes',
22+
hidden: false,
23+
)]
24+
class TuiCommand extends Command
25+
{
26+
protected function configure(): void
27+
{
28+
$this
29+
->setHelp('This command launches an interactive TUI to browse changes in your project dependencies')
30+
->addOption(
31+
'ignore-last',
32+
null,
33+
InputOption::VALUE_NONE,
34+
'Ignore last uncommitted changes'
35+
);
36+
}
37+
38+
protected function execute(InputInterface $input, OutputInterface $output): int
39+
{
40+
$ignoreLast = (bool) $input->getOption('ignore-last');
41+
42+
try {
43+
// Initialize services
44+
$git = new GitRepository();
45+
$packageInfoFetcher = new PackageInfoFetcher();
46+
$composerAnalyzer = new ComposerAnalyzer($packageInfoFetcher);
47+
$npmAnalyzer = new NpmAnalyzer($packageInfoFetcher);
48+
$diffCalculator = new DiffCalculator($git, $composerAnalyzer, $npmAnalyzer);
49+
50+
// Get package diffs
51+
$packageDiffs = $this->getPackageDiffs($diffCalculator, $ignoreLast);
52+
53+
if (empty($packageDiffs)) {
54+
$output->writeln('<info>No dependency changes detected.</info>');
55+
return Command::SUCCESS;
56+
}
57+
58+
// Launch TUI
59+
$tui = new TerminalUI($packageDiffs);
60+
$tui->prompt();
61+
62+
return Command::SUCCESS;
63+
64+
} catch (\Exception $e) {
65+
$output->writeln('<error>Error: ' . $e->getMessage() . '</error>');
66+
return Command::FAILURE;
67+
}
68+
}
69+
70+
private function getPackageDiffs(DiffCalculator $diffCalculator, bool $ignoreLast): array
71+
{
72+
// This method would need to be extracted from DiffCalculator
73+
// to return the package diffs data structure instead of printing to output
74+
// For now, returning a mock structure
75+
return [
76+
[
77+
'name' => 'example/package',
78+
'type' => 'composer',
79+
'from' => '1.0.0',
80+
'to' => '1.1.0',
81+
'status' => 'updated',
82+
'releases' => 3,
83+
],
84+
[
85+
'name' => 'another/package',
86+
'type' => 'composer',
87+
'from' => null,
88+
'to' => '2.0.0',
89+
'status' => 'added',
90+
'releases' => null,
91+
],
92+
];
93+
}
94+
}

0 commit comments

Comments
 (0)