Skip to content

feat: signal handling, ANSI auto-detect, verbosity levels, and command attributes#56

Merged
usernane merged 10 commits into
mainfrom
dev
Jun 13, 2026
Merged

feat: signal handling, ANSI auto-detect, verbosity levels, and command attributes#56
usernane merged 10 commits into
mainfrom
dev

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Release merge containing multiple feature additions to the CLI library.

Motivation

Address enterprise readiness: signal handling for graceful shutdown, modern CLI conventions for color output, verbosity control for automation, and PHP attributes for command metadata.

Changes

Signal Handling (#45)

  • SignalHandler class with register/remove/enable/disable API
  • Runner::enableSignalHandling() with default SIGINT/SIGTERM handlers
  • Per-command onSignal() cleanup registration
  • Graceful degradation on Windows

ANSI Auto-Detection (#50)

  • Runner::shouldUseAnsi() with TTY detection via posix_isatty
  • --no-color flag and NO_COLOR env support (no-color.org)
  • Resolution: --no-color > NO_COLOR env > --ansi > TTY detect

Verbosity Levels (#46)

  • Verbosity constants: QUIET, NORMAL, VERBOSE, DEBUG
  • -q, -v, -vv global flags
  • verbose() and debug() methods on Command
  • info()/success() suppressed in quiet mode

Command Attributes (#47, #49)

  • #[Group("name")] attribute for help display organization
  • #[SingleInstance] attribute with LockManager (flock-based)
  • resolveGroup() precedence: explicit > attribute > colon convention
  • Grouped help output in HelpCommand
  • Lock acquired before exec(), released in finally

Other

  • release-please-config.json: show all commit types in changelog
  • MIT license headers on all new files

How to Test / Verify

707 tests, 2083 assertions. 100% coverage on all new classes.

composer test

Breaking Changes and Migration Steps

  • Behavioral: Terminal output now has ANSI colors by default (use --no-color or NO_COLOR=1 to disable)
  • All other changes are opt-in and backward compatible

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) — ADR-0025 updated
  • I ran lint/cs-fixer (if applicable)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #45
Closes #46
Closes #47
Closes #49
Closes #50

Ibrahim BinAlshikh and others added 10 commits June 13, 2026 03:45
- Add SignalHandler class with register/remove/enable/disable API
- Add enableSignalHandling() and setSignalHandler() to Runner
- Add onSignal() per-command cleanup registration to Command
- Default SIGINT: exits with code 130 (interactive: interrupts command only)
- Default SIGTERM: sets shutdown flag, exits with code 143
- Graceful degradation on Windows (no-op when pcntl unavailable)
- Interactive mode loop respects shutdown flag for clean exit
- Per-command handlers auto-removed after command finishes

Closes #45
feat(runner): add signal handling support (SIGINT/SIGTERM)
- Add shouldUseAnsi() static method with TTY detection via posix_isatty
- Add --no-color global argument (respects no-color.org convention)
- Add isAnsi() public method to Runner
- Resolution precedence: --no-color > NO_COLOR env > --ansi > TTY detect
- Command println/prints now use Runner's resolved ANSI value
- Graceful Windows fallback via ANSICON/ConEmuANSI/TERM env checks
- ANSI only auto-enables when output stream is StdOut (not in tests)

Closes #50
Add hidden: false to all changelog-sections so commits like
fix(ci), test:, docs:, refactor:, etc. appear in the changelog.
feat(runner): ANSI colors on by default with TTY auto-detection
- Add Verbosity class with QUIET, NORMAL, VERBOSE, DEBUG constants
- Add -q, -v, -vv global arguments to Runner
- Add getVerbosity() and setVerbosity() to Runner
- Add verbose() and debug() methods to Command
- Gate info() and success() by verbosity (suppressed in quiet mode)
- error() and warning() always shown regardless of verbosity
- println() and prints() unchanged (unconditional primitives)
- Verbosity flags stripped from args passed to commands

Closes #46
feat(command): add verbosity levels (-q, -v, -vv)
- Add WebFiori\Cli\Attributes\Group attribute for help display grouping
- Add WebFiori\Cli\Attributes\SingleInstance attribute for lock-based
  single-instance enforcement
- Add LockManager class using flock() for non-blocking exclusive locks
- Add getGroup()/setGroup() to Command
- Add resolveGroup() with precedence: explicit > attribute > colon convention
- Integrate SingleInstance into excCommand() with try/finally lock release
- Update HelpCommand to display commands in groups when present
- Establish WebFiori\Cli\Attributes\ namespace per ADR-0025

Closes #47
Closes #49
feat(command): add #[Group] and #[SingleInstance] attributes
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.79288% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.36%. Comparing base (54c6bd6) to head (4912537).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
WebFiori/Cli/Runner.php 96.85% 14 Missing ⚠️
WebFiori/Cli/Commands/HelpCommand.php 88.78% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #56      +/-   ##
============================================
+ Coverage     87.72%   88.36%   +0.63%     
- Complexity     1322     1422     +100     
============================================
  Files            33       37       +4     
  Lines          3610     3858     +248     
============================================
+ Hits           3167     3409     +242     
- Misses          443      449       +6     
Flag Coverage Δ
php-8.1 88.36% <95.79%> (+0.63%) ⬆️
php-8.2 88.36% <95.79%> (+0.63%) ⬆️
php-8.3 88.36% <95.79%> (+0.63%) ⬆️
php-8.4 88.36% <95.79%> (+0.63%) ⬆️
php-8.5 88.33% <95.79%> (+0.63%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@usernane usernane merged commit 52cf653 into main Jun 13, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant