@@ -33,6 +33,8 @@ class Reader extends Runner\RepositoryAware
3333 public const OPT_ACTIONS = 'actions ' ;
3434 public const OPT_CONDITIONS = 'conditions ' ;
3535 public const OPT_OPTIONS = 'options ' ;
36+ public const OPT_CONFIG = 'config ' ;
37+ public const OPT_SETTINGS = 'settings ' ;
3638
3739 /**
3840 * The hook to display
@@ -42,9 +44,17 @@ class Reader extends Runner\RepositoryAware
4244 private array $ hooks = [];
4345
4446 /**
47+ * Default display options
48+ *
4549 * @var array<string, bool>
4650 */
47- private array $ options = [];
51+ private array $ options = [
52+ self ::OPT_ACTIONS => true ,
53+ self ::OPT_CONDITIONS => false ,
54+ self ::OPT_OPTIONS => false ,
55+ self ::OPT_CONFIG => false ,
56+ self ::OPT_SETTINGS => false ,
57+ ];
4858
4959 /**
5060 * Show more detailed information
@@ -109,20 +119,42 @@ public function run(): void
109119 if (!$ this ->config ->isLoadedFromFile ()) {
110120 throw new RuntimeException ('No configuration to read ' );
111121 }
122+ $ this ->displaySettings ();
123+ $ this ->io ->write ('<fg=magenta>Hooks:</> ' );
112124 foreach ($ this ->config ->getHookConfigs () as $ hookConfig ) {
113125 $ this ->displayHook ($ hookConfig );
114126 }
115127 }
116128
129+ /**
130+ * Display the application settings
131+ *
132+ * @return void
133+ */
134+ private function displaySettings (): void
135+ {
136+ if (!$ this ->show (self ::OPT_SETTINGS )) {
137+ return ;
138+ }
139+ $ this ->io ->write ('<fg=magenta>Config:</> ' );
140+ $ this ->io ->write (' - <fg=cyan>Verbosity:</fg=cyan> ' . $ this ->config ->getVerbosity ());
141+ $ this ->io ->write (' - <fg=cyan>Use colors:</fg=cyan> ' . $ this ->yesOrNo ($ this ->config ->useAnsiColors ()));
142+ $ this ->io ->write (' - <fg=cyan>Allow failures:</fg=cyan> ' . $ this ->yesOrNo ($ this ->config ->isFailureAllowed ()));
143+ $ this ->io ->write (' - <fg=cyan>Git directory:</fg=cyan> ' . $ this ->config ->getGitDirectory ());
144+ $ this ->io ->write (' - <fg=cyan>Bootstrap file:</fg=cyan> ' . $ this ->config ->getBootstrap ());
145+ $ this ->io ->write (' - <fg=cyan>Install mode:</fg=cyan> ' . $ this ->config ->getRunConfig ()->getMode ());
146+ }
147+
117148 /**
118149 * Display a hook configuration
150+ *
119151 * @param \CaptainHook\App\Config\Hook $config
120152 * @return void
121153 */
122154 private function displayHook (Config \Hook $ config ): void
123155 {
124156 if ($ this ->shouldHookBeDisplayed ($ config ->getName ())) {
125- $ this ->io ->write ('<info> ' . $ config ->getName () . '</info> ' , !$ this ->extensive );
157+ $ this ->io ->write (' <info> ' . $ config ->getName () . '</info> ' , !$ this ->extensive );
126158 $ this ->displayExtended ($ config );
127159 $ this ->displayActions ($ config );
128160 }
@@ -138,7 +170,7 @@ private function displayExtended(Config\Hook $config): void
138170 {
139171 if ($ this ->extensive ) {
140172 $ this ->io ->write (
141- ' ' . str_repeat ('- ' , 52 - strlen ($ config ->getName ())) .
173+ ' ' . str_repeat ('- ' , 50 - strlen ($ config ->getName ())) .
142174 '--[enabled: ' . $ this ->yesOrNo ($ config ->isEnabled ()) .
143175 ', installed: ' . $ this ->yesOrNo ($ this ->repository ->hookExists ($ config ->getName ())) . '] '
144176 );
@@ -166,8 +198,9 @@ private function displayActions(Config\Hook $config): void
166198 */
167199 private function displayAction (Config \Action $ action ): void
168200 {
169- $ this ->io ->write (' - <fg=cyan> ' . $ action ->getAction () . '</> ' );
201+ $ this ->io ->write (' - <fg=cyan> ' . $ action ->getAction () . '</> ' );
170202 $ this ->displayOptions ($ action ->getOptions ());
203+ $ this ->displayConfig ($ action );
171204 $ this ->displayConditions ($ action ->getConditions ());
172205 }
173206
@@ -182,16 +215,45 @@ private function displayOptions(Config\Options $options): void
182215 if (empty ($ options ->getAll ())) {
183216 return ;
184217 }
185- if ($ this ->show (self ::OPT_OPTIONS )) {
186- $ this ->io ->write (' <comment>Options:</comment> ' );
187- foreach ($ options ->getAll () as $ key => $ value ) {
188- $ this ->displayOption ($ key , $ value );
218+ if (!$ this ->show (self ::OPT_OPTIONS )) {
219+ return ;
220+ }
221+
222+ $ this ->io ->write (' <comment>Options:</comment> ' );
223+ foreach ($ options ->getAll () as $ key => $ value ) {
224+ $ this ->displayOption ($ key , $ value );
225+ }
226+ }
227+
228+ /**
229+ * Display all action config values
230+ *
231+ * @param \CaptainHook\App\Config\Action $action
232+ * @return void
233+ */
234+ private function displayConfig (Config \Action $ action ): void
235+ {
236+ if (!$ this ->show (self ::OPT_CONFIG )) {
237+ return ;
238+ }
239+
240+ $ config = [];
241+ if ($ action ->getLabel () != $ action ->getAction ()) {
242+ $ config ['label ' ] = $ action ->getLabel ();
243+ }
244+ if ($ action ->isFailureAllowed ()) {
245+ $ config ['failureAllowed ' ] = true ;
246+ }
247+ if (!empty ($ config )) {
248+ $ this ->io ->write (' <comment>Config:</comment> ' );
249+ foreach ($ config as $ key => $ value ) {
250+ $ this ->io ->write (' - ' . $ key . ': <fg=gray> ' . $ value . '</> ' );
189251 }
190252 }
191253 }
192254
193255 /**
194- * Display a singe option
256+ * Display a single option
195257 *
196258 * @param mixed $key
197259 * @param mixed $value
@@ -203,7 +265,7 @@ private function displayOption(mixed $key, mixed $value, string $prefix = ''): v
203265 if (is_array ($ value )) {
204266 $ value = implode (', ' , $ value );
205267 }
206- $ this ->io ->write ($ prefix . ' - ' . $ key . ': ' . $ value );
268+ $ this ->io ->write ($ prefix . ' - ' . $ key . ': <fg=gray> ' . $ value . ' </> ' );
207269 }
208270
209271 /**
@@ -218,13 +280,15 @@ private function displayConditions(array $conditions, string $prefix = ''): void
218280 if (empty ($ conditions )) {
219281 return ;
220282 }
221- if ($ this ->show (self ::OPT_CONDITIONS )) {
222- if (empty ($ prefix )) {
223- $ this ->io ->write ($ prefix . ' <comment>Conditions:</comment> ' );
224- }
225- foreach ($ conditions as $ condition ) {
226- $ this ->displayCondition ($ condition , $ prefix );
227- }
283+ if (!$ this ->show (self ::OPT_CONDITIONS )) {
284+ return ;
285+ }
286+
287+ if (empty ($ prefix )) {
288+ $ this ->io ->write ($ prefix . ' <comment>Conditions:</comment> ' );
289+ }
290+ foreach ($ conditions as $ condition ) {
291+ $ this ->displayCondition ($ condition , $ prefix );
228292 }
229293 }
230294
@@ -237,7 +301,7 @@ private function displayConditions(array $conditions, string $prefix = ''): void
237301 */
238302 private function displayCondition (Config \Condition $ condition , string $ prefix = '' ): void
239303 {
240- $ this ->io ->write ($ prefix . ' - ' . $ condition ->getExec ());
304+ $ this ->io ->write ($ prefix . ' - <fg=cyan> ' . $ condition ->getExec () . ' </> ' );
241305
242306 if (in_array (strtoupper ($ condition ->getExec ()), ['OR ' , 'AND ' ])) {
243307 $ conditions = [];
@@ -251,7 +315,7 @@ private function displayCondition(Config\Condition $condition, string $prefix =
251315 if (empty ($ condition ->getArgs ())) {
252316 return ;
253317 }
254- $ this ->io ->write ($ prefix . ' <comment>Args:</comment> ' );
318+ $ this ->io ->write ($ prefix . ' <comment>Args:</comment> ' );
255319 foreach ($ condition ->getArgs () as $ key => $ value ) {
256320 $ this ->displayOption ($ key , $ value , $ prefix . ' ' );
257321 }
@@ -266,9 +330,6 @@ private function displayCondition(Config\Condition $condition, string $prefix =
266330 */
267331 private function show (string $ option ): bool
268332 {
269- if (empty ($ this ->options )) {
270- return true ;
271- }
272333 return $ this ->options [$ option ] ?? false ;
273334 }
274335
0 commit comments