Skip to content

Commit 54173e7

Browse files
authored
Merge branch 'main' into fix-slash-in-enum-values
2 parents edb221b + c1561e0 commit 54173e7

File tree

58 files changed

+775
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+775
-125
lines changed

.gitattributes

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Fix line endings for Windows
2+
tempest text=auto eol=lf
3+
bin/* text=auto eol=lf
4+
packages/console/bin/tempest text=auto eol=lf
5+
packages/console/src/Installers/tempest text=auto eol=lf
6+
src/Tempest/Framework/Installers/tempest text=auto eol=lf
7+
18
# Exclude build/test files from the release
29
/bin/ export-ignore
310
.github/ export-ignore
@@ -15,5 +22,9 @@ rector.php export-ignore
1522
cliff.toml export-ignore
1623
.commitlintrc.json export-ignore
1724

18-
# Configure diff output for .php and .phar files.
25+
# Configure diff output
26+
*.view.php diff=html
1927
*.php diff=php
28+
*.css diff=css
29+
*.html diff=html
30+
*.md diff=markdown

packages/auth/.gitattributes

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ tests/ export-ignore
66
phpunit.xml export-ignore
77
README.md export-ignore
88

9-
# Configure diff output for .php and .phar files.
9+
# Configure diff output
10+
*.view.php diff=html
1011
*.php diff=php
12+
*.css diff=css
13+
*.html diff=html
14+
*.md diff=markdown

packages/cache/.gitattributes

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ tests/ export-ignore
66
phpunit.xml export-ignore
77
README.md export-ignore
88

9-
# Configure diff output for .php and .phar files.
10-
*.php diff=php
9+
# Configure diff output
10+
*.view.php diff=html
11+
*.php diff=php
12+
*.css diff=css
13+
*.html diff=html
14+
*.md diff=markdown

packages/clock/.gitattributes

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ tests/ export-ignore
66
phpunit.xml export-ignore
77
README.md export-ignore
88

9-
# Configure diff output for .php and .phar files.
10-
*.php diff=php
9+
# Configure diff output
10+
*.view.php diff=html
11+
*.php diff=php
12+
*.css diff=css
13+
*.html diff=html
14+
*.md diff=markdown

packages/command-bus/.gitattributes

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ tests/ export-ignore
66
phpunit.xml export-ignore
77
README.md export-ignore
88

9-
# Configure diff output for .php and .phar files.
10-
*.php diff=php
9+
# Configure diff output
10+
*.view.php diff=html
11+
*.php diff=php
12+
*.css diff=css
13+
*.html diff=html
14+
*.md diff=markdown

packages/console/.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
# Fix line endings for Windows
2+
bin/tempest text=auto eol=lf
3+
src/Installers/tempest text=auto eol=lf
4+
15
# Exclude build/test files from the release
26
.github/ export-ignore
7+
tests/ export-ignore
38
.gitattributes export-ignore
49
.gitignore export-ignore
10+
phpunit.xml export-ignore
511
README.md export-ignore
12+
13+
# Configure diff output
14+
*.view.php diff=html
15+
*.php diff=php
16+
*.css diff=css
17+
*.html diff=html
18+
*.md diff=markdown

packages/console/src/Console.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,34 @@ interface Console
1515
{
1616
public function call(string|array $command, string|array $arguments = []): ExitCode|int;
1717

18+
/**
19+
* Reads a line from the console input.
20+
*/
1821
public function readln(): string;
1922

23+
/**
24+
* Reads the specified number of bytes from the console input.
25+
*/
2026
public function read(int $bytes): string;
2127

28+
/**
29+
* Writes the specified `$contents` to the console output.
30+
*/
2231
public function write(string $contents): self;
2332

33+
/**
34+
* Writes the specified `$contents` to the console output and appends a new line.
35+
*/
2436
public function writeln(string $line = ''): self;
2537

38+
/**
39+
* Writes the specified `$contents` to the console output, without formatting.
40+
*/
2641
public function writeRaw(string $contents): self;
2742

43+
/**
44+
* Writes the specified `$contents` to the console output with the specified syntax highlighting.
45+
*/
2846
public function writeWithLanguage(string $contents, Language $language): self;
2947

3048
/**
@@ -33,6 +51,8 @@ public function writeWithLanguage(string $contents, Language $language): self;
3351
public function component(InteractiveConsoleComponent $component, array $validation = []): mixed;
3452

3553
/**
54+
* Asks the user a question and returns the answer.
55+
*
3656
* @param null|array|iterable|class-string<BackedEnum> $options
3757
* @param mixed|null $default
3858
* @param \Tempest\Validation\Rule[] $validation
@@ -48,48 +68,93 @@ public function ask(
4868
array $validation = [],
4969
): null|int|string|Stringable|UnitEnum|array;
5070

71+
/**
72+
* Asks the user a question and returns the answer.
73+
*/
5174
public function confirm(string $question, bool $default = false, ?string $yes = null, ?string $no = null): bool;
5275

76+
/**
77+
* Prompts the user for a password and returns it.
78+
*/
5379
public function password(string $label = 'Password', bool $confirm = false, array $validation = []): ?string;
5480

81+
/**
82+
* Progresses through the specified `$data` using the specified `$handler`.
83+
*/
5584
public function progressBar(iterable $data, Closure $handler): array;
5685

5786
/**
87+
* Asks the user to select an option from a list using a closure.
88+
*
5889
* @param Closure(string $search): array $search
5990
*/
6091
public function search(string $label, Closure $search, bool $multiple = false, null|string|array $default = null): mixed;
6192

93+
/**
94+
* Displays the progress of a task.
95+
*/
6296
public function task(string $label, null|Process|Closure $handler): bool;
6397

98+
/**
99+
* Displays a header.
100+
*/
64101
public function header(string $header, ?string $subheader = null): self;
65102

103+
/**
104+
* Displays information to the user.
105+
*/
66106
public function info(string $contents, ?string $title = null): self;
67107

108+
/**
109+
* Displays an error message to the user.
110+
*/
68111
public function error(string $contents, ?string $title = null): self;
69112

113+
/**
114+
* Displays a warning to the user.
115+
*/
70116
public function warning(string $contents, ?string $title = null): self;
71117

118+
/**
119+
* Displays a success message to the user.
120+
*/
72121
public function success(string $contents, ?string $title = null): self;
73122

123+
/**
124+
* Displays a key/value pair in a line.
125+
*/
74126
public function keyValue(string $key, ?string $value = null, bool $useAvailableWidth = false): self;
75127

128+
/**
129+
* Displays instructions to the user. Can be an array of lines.
130+
*/
76131
public function instructions(array|string $lines): self;
77132

78133
/**
134+
* Applies the specified `$callback` when the `$condition` is `true`.
135+
*
79136
* @param mixed|Closure(self): bool $condition
80137
* @param Closure(self): self $callback
81138
*/
82139
public function when(mixed $condition, Closure $callback): self;
83140

84141
/**
142+
* Applies the specified `$callback` unless the `$condition` is `true`.
143+
*
85144
* @param mixed|Closure(self): bool $condition
86145
* @param Closure(self): self $callback
87146
*/
88147
public function unless(mixed $condition, Closure $callback): self;
89148

90149
public function withLabel(string $label): self;
91150

151+
/**
152+
* Whether the console is interactive.
153+
*/
92154
public function supportsPrompting(): bool;
93155

156+
/**
157+
* Forces the console to not be interactive.
158+
*/
94159
public function disablePrompting(): self;
95160
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Tempest\Console\Exceptions;
4+
5+
use Tempest\Console\Console;
6+
use Tempest\Console\ConsoleCommand;
7+
use Tempest\Console\Input\ConsoleInputArgument;
8+
use Tempest\Support\Arr\ImmutableArray;
9+
10+
final class UnknownArgumentsException extends ConsoleException
11+
{
12+
public function __construct(
13+
private readonly ConsoleCommand $consoleCommand,
14+
/** @var \Tempest\Console\Input\ConsoleInputArgument[] $invalidArguments */
15+
private readonly ImmutableArray $invalidArguments,
16+
) {}
17+
18+
public function render(Console $console): void
19+
{
20+
$console->error(sprintf(
21+
'Unknown arguments: %s',
22+
$this->invalidArguments
23+
->map(fn (ConsoleInputArgument $argument) => sprintf(
24+
'<code>%s</code>',
25+
$argument->name,
26+
))
27+
->implode(', '),
28+
));
29+
}
30+
}

packages/console/src/GenericConsole.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public function supportsPrompting(): bool
310310
return false;
311311
}
312312

313-
if ($this->argumentBag->get('interaction')?->value === false) {
313+
if ($this->argumentBag->get(GlobalFlags::INTERACTION->value)?->value === false) {
314314
return false;
315315
}
316316

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Tempest\Console;
4+
5+
use Tempest\Support\IsEnumHelper;
6+
7+
enum GlobalFlags: string
8+
{
9+
use IsEnumHelper;
10+
11+
case FORCE = 'force';
12+
case FORCE_SHORTHAND = '-f';
13+
case HELP = 'help';
14+
case HELP_SHORTHAND = '-h';
15+
case INTERACTION = 'interaction';
16+
}

0 commit comments

Comments
 (0)