-
-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Description
For example ansi style color code on action output results is interpreted by CaptainHook and break render.
' <fg=cyan>Applied: ' .
I've tested Mago 1.9.0 with my plugin
Capt'n config file examples/pre-push.mago.json
{
"pre-push": {
"enabled": true,
"actions": [
{
"action": "{$ENV|value-of:VENDOR_BIN_DIR|default:vendor/bin/}mago lint",
"config": {
"label": "Static Analysis (with Mago)"
},
"options": {
"configuration-path": "mago.toml",
"colors": "never"
},
"conditions": [
{
"exec": "\\Bartlett\\CaptainHookBinPlugin\\Condition\\PackageInstalled",
"args": ["carthage-software/mago", "^1"]
}
]
}
]
}
}Note
The mago.toml config file is generated to answered all default values to vendor/bin/mago init command
My Plugin (under tests pressure)
<?php
declare(strict_types=1);
namespace Bartlett\CaptainHookBinPlugin;
use CaptainHook\App\Config;
use CaptainHook\App\Plugin;
use CaptainHook\App\Runner\Hook as RunnerHook;
class BinPlugin extends Plugin\Hook\Base implements Plugin\Hook
{
public function beforeHook(RunnerHook $hook): void
{
$this->io->write("Do debug before hook {$hook->getName()} runs");
}
public function beforeAction(RunnerHook $hook, Config\Action $action): void
{
$actionOptions = $action->getOptions();
$configPath = $actionOptions->get('configuration-path');
if (null !== $configPath && \file_exists($configPath)) {
\putenv('XDG_CONFIG_HOME=' . $configPath);
}
$colorized = match($actionOptions->get('colors', 'auto')) {
'never' => false,
default => true // always or auto values are acceptable
};
\putenv('NO_COLOR=' . !$colorized);
$this->io->write("Do debug before action {$action->getLabel()} runs");
}
public function afterAction(RunnerHook $hook, Config\Action $action): void
{
$this->io->write("Do debug after action {$action->getLabel()} runs");
\putenv('XDG_CONFIG_HOME');
}
public function afterHook(RunnerHook $hook): void
{
$this->io->write("Do debug after hook {$hook->getName()} runs");
}
}Mago accept both XDG_CONFIG_HOME and NO_COLOR environment variables : see https://mago.carthage.software/guide/environment-variables
Direct invocation of Mago
XDG_CONFIG_HOME=mago.toml NO_COLOR=1 vendor/bin/mago lintGave something like (with current state source code)
Capt'n invocation of Mago
vendor/bin/captainhook hook:pre-push -vvImportant
Due to issue #299, I cannot invoke only one action by config file, so I've disabled all others (PHPStan, PHPUnit) confirmed by command
vendor/bin/captainhook config:infoHooks:
commit-msg
pre-push
- {$ENV|value-of:VENDOR_BIN_DIR|default:vendor/bin/}mago lint
pre-commit
prepare-commit-msg
post-commit
post-merge
post-checkout
post-rewrite
post-change
Gave something like (with current state source code)
And if I've other actions, the color render is still broken: i.e

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels