Skip to content

Commit 6c985fe

Browse files
committed
added CLAUDE.md
1 parent 1d30eb1 commit 6c985fe

2 files changed

Lines changed: 188 additions & 0 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.gitattributes export-ignore
22
.github/ export-ignore
33
.gitignore export-ignore
4+
CLAUDE.md export-ignore
45
ncs.* export-ignore
56
phpstan*.neon export-ignore
67
tests/ export-ignore

CLAUDE.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
**Nette Command Line** is a lightweight PHP library providing two focused utilities:
8+
- `Parser`: Command-line argument and option parsing with help text extraction
9+
- `Console`: Terminal color output with intelligent capability detection
10+
11+
**Key characteristics:**
12+
- Zero runtime dependencies (PHP 8.2-8.5 only)
13+
- Minimal codebase (~274 LOC total)
14+
- Part of the Nette Framework ecosystem
15+
- Triple-licensed: BSD-3-Clause, GPL-2.0-only, GPL-3.0-only
16+
17+
## Essential Commands
18+
19+
### Development Setup
20+
```bash
21+
composer install # Install dev dependencies
22+
```
23+
24+
### Testing
25+
```bash
26+
composer run tester # Run all tests with simple output
27+
vendor/bin/tester tests -s # Same as above
28+
vendor/bin/tester tests -s # Run with code coverage
29+
vendor/bin/tester tests/Parser.phpt -s # Run specific test file
30+
```
31+
32+
### Code Quality
33+
```bash
34+
composer run phpstan # Run PHPStan static analysis (level 5)
35+
```
36+
37+
### CI/CD Information
38+
- Tests run on PHP 8.2, 8.3, 8.4, 8.5 via GitHub Actions
39+
- Coding style checked via Nette Code Checker and Coding Standard
40+
- PHPStan runs on master branch (informative only)
41+
42+
## Architecture
43+
44+
### Two-Class Design
45+
46+
**Parser (`src/CommandLine/Parser.php` - 209 lines)**
47+
- Parses command-line arguments using help text as schema definition
48+
- Extracts option definitions via regex from formatted help strings
49+
- Supports: flags, arguments, aliases, default values, enums, file paths, custom normalizers
50+
- Modern PascalCase constants (e.g., `Parser::Argument`, `Parser::Optional`)
51+
- Deprecated UPPERCASE constants maintained for backward compatibility
52+
53+
**Console (`src/CommandLine/Console.php` - 65 lines)**
54+
- ANSI color output with automatic terminal capability detection
55+
- Respects `NO_COLOR` environment variable (https://no-color.org)
56+
- Detects Windows VT100 support and TTY environments
57+
- 16 named colors with foreground/background combinations
58+
59+
### Key Design Patterns
60+
61+
**Help Text as Schema:**
62+
The Parser class uses regex to extract option definitions from formatted help text:
63+
64+
```php
65+
$cmd = new Parser('
66+
-p, --param=<value> Parameter description (default: 123)
67+
--verbose Enable verbose mode
68+
');
69+
```
70+
71+
The help text format drives the parser configuration - options, arguments, defaults, and enums are all extracted from the help string structure.
72+
73+
**Option Configuration Array:**
74+
Options can be configured via the second constructor parameter using constants:
75+
- `Parser::Argument` - requires a value
76+
- `Parser::Optional` - value is optional
77+
- `Parser::Repeatable` - can be specified multiple times
78+
- `Parser::Enum` - restricted to specific values
79+
- `Parser::RealPath` - validates file path existence
80+
- `Parser::Normalizer` - custom transformation function
81+
- `Parser::Default` - default value when not specified
82+
83+
## Coding Standards
84+
85+
### Nette Framework Conventions
86+
- Every file: `declare(strict_types=1)` at the top
87+
- Tab indentation (not spaces)
88+
- Comprehensive type hints on all parameters and return values
89+
- PSR-12 inspired with Nette-specific modifications
90+
- Minimal but clear documentation
91+
92+
### Naming Conventions
93+
- PascalCase for class constants (modern style, e.g., `Parser::Optional`)
94+
- camelCase for methods and properties
95+
- Deprecated UPPERCASE constants aliased to PascalCase equivalents
96+
97+
### Documentation Style
98+
- Classes: Brief description without unnecessary verbosity (e.g., "Stupid command line arguments parser")
99+
- Methods: Document when adding value beyond type signatures
100+
- Properties: Inline `@var` annotations for complex types
101+
102+
## Testing with Nette Tester
103+
104+
### Test File Structure
105+
Files use `.phpt` extension and follow this pattern:
106+
107+
```php
108+
<?php
109+
110+
declare(strict_types=1);
111+
112+
use Nette\CommandLine\Parser;
113+
use Tester\Assert;
114+
115+
require __DIR__ . '/bootstrap.php';
116+
117+
118+
test('description of what is tested', function () {
119+
$cmd = new Parser('...');
120+
Assert::same(['expected'], $cmd->parse(['input']));
121+
});
122+
123+
124+
test('another test case', function () {
125+
// Test implementation
126+
});
127+
```
128+
129+
### Testing Patterns
130+
- Use `test()` function for each test case with clear descriptions
131+
- No comments before `test()` calls - the description parameter serves this purpose
132+
- Group related tests in the same file
133+
- Use `Assert::same()` for exact equality checks
134+
- Use `Assert::exception()` for exception testing
135+
136+
### Bootstrap Setup
137+
All tests require `require __DIR__ . '/bootstrap.php';` which:
138+
- Loads Composer autoloader
139+
- Configures Tester environment
140+
- Sets up test functions
141+
142+
## Version Management
143+
144+
**Current branch:** master (1.8-dev)
145+
**PHP Support:** 8.0 minimum, tested through 8.5
146+
**Branch alias:** dev-master → 1.8-dev
147+
148+
### Backward Compatibility
149+
- Deprecated constants maintained with `@deprecated` annotations
150+
- Old UPPERCASE constants aliased to new PascalCase versions
151+
- Breaking changes noted in commit messages with "(BC break)"
152+
153+
## Common Development Scenarios
154+
155+
### Adding Parser Features
156+
When extending the Parser class:
157+
1. Add new constants in PascalCase format
158+
2. Create UPPERCASE deprecated aliases if replacing old names
159+
3. Update help text regex in constructor if needed
160+
4. Add comprehensive tests in `tests/Parser.phpt`
161+
5. Consider enum validation and normalizer patterns
162+
163+
### Console Color Additions
164+
When modifying Console output:
165+
1. Respect `$this->useColors` flag
166+
2. Return plain strings when colors disabled
167+
3. Test with `NO_COLOR` environment variable
168+
4. Consider cross-platform compatibility (Windows VT100)
169+
170+
### Test Writing
171+
1. Create or extend `.phpt` files in `tests/` directory
172+
2. Use descriptive test names in `test()` function
173+
3. Cover both success and error cases
174+
4. Test edge cases (empty input, missing values, invalid formats)
175+
176+
## Dependencies and Tooling
177+
178+
**Runtime:** None (PHP 8.0+ only)
179+
180+
**Development:**
181+
- `nette/tester` ^2.5 - Testing framework
182+
- `tracy/tracy` ^2.9 - Debugging and error handling
183+
- `phpstan/phpstan-nette` ^2.0 - Static analysis with Nette-specific rules
184+
185+
**Autoloading:**
186+
- PSR-4: `Nette\``src/`
187+
- Classmap fallback for `src/` directory

0 commit comments

Comments
 (0)