Skip to content

Commit 1ee57be

Browse files
Show action detail if --action is supplied
Only skip action display if only the app config settings are requested. As soon as a hook arg is given show at least the label-only version of the actions.
1 parent 739e317 commit 1ee57be

4 files changed

Lines changed: 51 additions & 38 deletions

File tree

src/Runner/Config/Visualizer.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ public function run(): void
128128
if (!$this->config->isLoadedFromFile()) {
129129
throw new RuntimeException('No configuration to read');
130130
}
131-
// make sure to display the necessary parts of the configuration
132-
$this->settings->sanityCheck();
133-
134-
// if at least one hook is given, display the hook actions
135-
if (count($this->hooks)) {
136-
$this->settings->set(Visualizer\Settings::OPT_ACTIONS, true);
137-
}
138131

139132
$this->output->printHeader($this->config);
140133
$this->displaySettings();
@@ -165,7 +158,7 @@ private function displaySettings(): void
165158
*/
166159
private function displayHooks(): void
167160
{
168-
if (!$this->settings->show(Visualizer\Settings::OPT_ACTIONS)) {
161+
if ($this->isApplicationSettingsOnly()) {
169162
return;
170163
}
171164
$this->output->printHooks($this->hooksToDisplay(), $this->extensive);
@@ -200,4 +193,37 @@ private function shouldHookBeDisplayed(string $name): bool
200193
}
201194
return in_array($name, $this->hooks);
202195
}
196+
197+
/**
198+
* Check if only the application settings should be displayed
199+
*
200+
* @return bool
201+
*/
202+
private function isApplicationSettingsOnly(): bool
203+
{
204+
// no app config to display, so clearly no
205+
if (!$this->settings->show(Visualizer\Settings::OPT_SETTINGS)) {
206+
return false;
207+
}
208+
209+
// check if any action-related stuff has to be shown
210+
$actionRelatedStuff = [
211+
Visualizer\Settings::OPT_ACTIONS,
212+
Visualizer\Settings::OPT_CONDITIONS,
213+
Visualizer\Settings::OPT_OPTIONS,
214+
Visualizer\Settings::OPT_CONFIG,
215+
];
216+
// if so app config is not the only thing to display
217+
foreach ($actionRelatedStuff as $option) {
218+
if ($this->settings->show($option)) {
219+
return false;
220+
}
221+
}
222+
// if we display a specific hook showing the actions makes sense
223+
if (!empty($this->hooks)) {
224+
return false;
225+
}
226+
// otherwise we display only the app config
227+
return true;
228+
}
203229
}

src/Runner/Config/Visualizer/Output.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function printActions(Config\Hook $config): void
220220
public function printAction(Config\Action $action): void
221221
{
222222
$this->io->write(' - <fg=cyan>' . $action->getLabel() . '</>');
223-
if ($action->hasLabel()) {
223+
if ($action->hasLabel() && $this->settings->show(Settings::OPT_ACTIONS)) {
224224
$this->io->write(' <fg=gray>' . $action->getAction() . '</>');
225225
}
226226
$this->printOptions($action->getOptions());

src/Runner/Config/Visualizer/Settings.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,4 @@ public function show(string $option): bool
6464
{
6565
return $this->options[$option] ?? false;
6666
}
67-
68-
/**
69-
* Check if no config part should be shown
70-
*
71-
* @return void
72-
*/
73-
public function sanityCheck(): void
74-
{
75-
$displayAnything = false;
76-
foreach ($this->options as $option) {
77-
if ($option) {
78-
$displayAnything = true;
79-
break;
80-
}
81-
}
82-
// nothing should be displayed, show actions by default
83-
if (!$displayAnything) {
84-
$this->options[self::OPT_ACTIONS] = true;
85-
return;
86-
}
87-
88-
// check for anything that needs actions to be displayed
89-
foreach ([self::OPT_CONDITIONS, self::OPT_OPTIONS, self::OPT_CONFIG] as $option) {
90-
if ($this->options[$option]) {
91-
$this->options[self::OPT_ACTIONS] = true;
92-
return;
93-
}
94-
}
95-
}
9667
}

tests/unit/Runner/Config/VisualizerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ public function testDoesNotShowActionForAppSettings(): void
111111
->run();
112112
}
113113

114+
public function testDoesShowActionsForAppSettingsWithHookArgument(): void
115+
{
116+
$path = realpath(CH_PATH_FILES . '/config/valid.json');
117+
$config = Config\Factory::create($path);
118+
$io = $this->createIOMock();
119+
$repo = $this->createRepositoryMock();
120+
121+
// the better thing to test would be to really check the output
122+
$io->expects($this->atMost(11))->method('write');
123+
124+
$runner = new Visualizer($io, $config, $repo);
125+
$runner->display(Visualizer\Settings::OPT_SETTINGS, true)
126+
->setHook('pre-commit')
127+
->run();
128+
}
129+
114130
public function testItDisplaysOnlyActions(): void
115131
{
116132
$path = realpath(CH_PATH_FILES . '/config/valid.json');

0 commit comments

Comments
 (0)