Skip to content

Commit 9eac1f3

Browse files
committed
feat: introduce Command value object and refactor CommandsExecutor for improved command handling
1 parent a9c82a1 commit 9eac1f3

13 files changed

+170
-257
lines changed

context.yaml

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,30 @@
1-
$schema: https://raw.githubusercontent.com/context-hub/generator/refs/heads/main/json-schema.json
1+
$schema: 'https://raw.githubusercontent.com/context-hub/generator/refs/heads/main/json-schema.json'
22

33
import:
4-
- path: src/*/context.yaml
4+
- path: src/**/context.yaml
5+
6+
variables:
7+
name: Context Generator
8+
9+
prompts:
10+
- id: my-local-prompt
11+
description: My local prompt
12+
messages:
13+
- role: user
14+
content: |
15+
You are an expert in generating {{name}}. You love your work and always aim for clean, efficient, and
16+
well-structured PHP code, focusing on detail and best practices.
517
618
documents:
7-
- description: "Context Generator Project Structure"
8-
outputPath: "project-structure.md"
19+
- description: 'Project structure overview'
20+
outputPath: project-structure.md
21+
overwrite: true
922
sources:
1023
- type: tree
1124
sourcePaths:
1225
- src
1326
showCharCount: true
1427
showSize: true
15-
dirContext:
16-
"src": "Root directory containing all Context Generator source code."
17-
"src/ConfigLoader": "Configuration loading system that reads, parses, and validates config files in JSON, PHP, and YAML formats."
18-
"src/Console": "Command-line interface components providing user interaction through commands."
19-
"src/Document": "Document definition and compilation system that transforms source content into output files."
20-
"src/Fetcher": "Content fetching interfaces and registry for retrieving data from various sources."
21-
"src/Lib": "Utility libraries providing supporting functionality for the core components."
22-
"src/Modifier": "Content transformation system for filtering, formatting, and sanitizing source content."
23-
"src/Source": "Source implementations for various content locations (files, URLs, GitHub, etc.)."
24-
"src/Source/Composer": "Composer integration for accessing package dependencies."
25-
"src/Source/File": "Local filesystem source implementation."
26-
"src/Source/GitDiff": "Git diff source for accessing changes in repositories."
27-
"src/Source/Github": "GitHub API integration for remote repository access."
28-
"src/Source/Text": "Text source for embedding custom content."
29-
"src/Source/Tree": "Directory structure visualization source."
30-
"src/Source/Url": "Web URL source for retrieving online content."
31-
"src/Lib/Content": "Content building and rendering system for structured document output."
32-
"src/Lib/Finder": "File discovery components for locating content across different storage types."
33-
"src/Lib/GithubClient": "GitHub API client for repository access."
34-
"src/Lib/Html": "HTML processing utilities for web content."
35-
"src/Lib/HttpClient": "HTTP client abstraction for web requests."
36-
"src/Lib/Logger": "Logging system for operation visibility."
37-
"src/Lib/PathFilter": "Path filtering utilities for including/excluding content by pattern."
38-
"src/Lib/Sanitizer": "Content sanitization for removing sensitive information."
39-
"src/Lib/TreeBuilder": "Tree visualization generation for directory structures."
40-
"src/Lib/Variable": "Variable substitution system for configuration values."
41-
description: >-
42-
A hierarchical visualization of the Context Generator project structure, showing
43-
the main directories and files with explanations of their purpose. This provides
44-
a high-level overview of the project organization and helps understand the
45-
relationships between different components.
4628

4729
- description: Core Interfaces
4830
outputPath: core/interfaces.md
@@ -51,17 +33,6 @@ documents:
5133
sourcePaths: src
5234
filePattern:
5335
- '*Interface.php'
54-
- 'SourceInterface.php'
55-
- 'SourceModifierInterface.php'
56-
- 'FilesInterface.php'
57-
showTreeView: true
58-
59-
- description: Config parser
60-
outputPath: core/config-parser.md
61-
sources:
62-
- type: file
63-
sourcePaths: src/ConfigLoader
64-
filePattern: '*.php'
6536
showTreeView: true
6637

6738
- description: "Changes in the Project"

src/Lib/Git/Command.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Butschster\ContextGenerator\Lib\Git;
6+
7+
/**
8+
* A value object that represents a Git command to be executed.
9+
*/
10+
final readonly class Command implements \Stringable
11+
{
12+
/**
13+
* @param string $repository Path to the Git repository
14+
* @param array<string>|string $command Git command to execute (without 'git' prefix)
15+
*/
16+
public function __construct(
17+
public string $repository,
18+
private array|string $command,
19+
) {}
20+
21+
/**
22+
* Get the command as an array.
23+
*
24+
* @return array<string>
25+
*/
26+
public function getCommandParts(): array
27+
{
28+
if (\is_array($this->command)) {
29+
return $this->command;
30+
}
31+
32+
$command = \trim($this->command);
33+
34+
// If the command already starts with 'git', remove it
35+
if (\str_starts_with($command, 'git ')) {
36+
$command = \substr($command, 4);
37+
}
38+
39+
return \array_filter(\explode(' ', $command));
40+
}
41+
42+
public function __toString(): string
43+
{
44+
if (\is_string($this->command)) {
45+
$command = \trim($this->command);
46+
47+
// If the command already starts with 'git', use it as is
48+
if (\str_starts_with($command, 'git ')) {
49+
$command = \substr($command, 4);
50+
}
51+
52+
return $command;
53+
}
54+
55+
return \implode(' ', $this->command);
56+
}
57+
}

0 commit comments

Comments
 (0)