Skip to content

feat(command): add #[Group] and #[SingleInstance] attributes#55

Merged
usernane merged 1 commit into
devfrom
feat/command-attributes
Jun 13, 2026
Merged

feat(command): add #[Group] and #[SingleInstance] attributes#55
usernane merged 1 commit into
devfrom
feat/command-attributes

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Introduce PHP 8.1 attributes for command metadata, establishing the WebFiori\Cli\Attributes\ namespace per ADR-0025.

Motivation

Closes #47, Closes #49.

Changes

New files

  • WebFiori/Cli/Attributes/Group.php#[Group("name")] for help display grouping
  • WebFiori/Cli/Attributes/SingleInstance.php#[SingleInstance] for lock-based concurrency prevention
  • WebFiori/Cli/LockManager.php — flock-based non-blocking exclusive locks with PID tracking

Modified files

  • Command.php — added group property, getGroup()/setGroup(), resolveGroup(), resolveSingleInstance(), integrated lock into excCommand() with try/finally
  • Runner.php — calls resolveGroup() on register
  • HelpCommand.php — grouped output when groups exist (alphabetical, ungrouped last)

Resolution precedence (Group):

  1. Explicit setGroup() (programmatic)
  2. #[Group] attribute
  3. Colon prefix in name (db:migratedb)

SingleInstance behavior:

  • Lock acquired before exec(), released in finally
  • OS releases flock on crash/SIGKILL
  • Custom lockPath and exitCode supported

How to Test / Verify

  • tests/WebFiori/Tests/Cli/LockManagerTest.php (7 tests)
  • tests/WebFiori/Tests/Cli/CommandAttributesTest.php (12 tests)

Run: composer test

Breaking Changes and Migration Steps

None. Commands without attributes behave exactly as before.

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 to Accepted
  • I ran lint/cs-fixer (if applicable) (composer fix-cs)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #47
Closes #49

- 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
@usernane usernane merged commit 9833f63 into dev Jun 13, 2026
1 check passed
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.51351% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.36%. Comparing base (14b17ef) to head (fa6475a).
⚠️ Report is 3 commits behind head on dev.

Files with missing lines Patch % Lines
WebFiori/Cli/Commands/HelpCommand.php 88.78% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                dev      #55      +/-   ##
============================================
+ Coverage     88.08%   88.36%   +0.27%     
- Complexity     1317     1350      +33     
============================================
  Files            34       37       +3     
  Lines          3768     3858      +90     
============================================
+ Hits           3319     3409      +90     
  Misses          449      449              
Flag Coverage Δ
php-8.3 88.36% <93.51%> (+0.27%) ⬆️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant