Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass errorLevel="suppress" />
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ interface Command
/**
* @return Attempt<Console>
*/
#[\NoDiscard]
public function __invoke(Console $console): Attempt;

/**
* @psalm-mutation-free
*/
#[\NoDiscard]
public function usage(): Usage;
}
4 changes: 4 additions & 0 deletions src/Command/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(?Map $arguments = null, ?Sequence $pack = null)
$this->pack = $pack ?? Sequence::strings();
}

#[\NoDiscard]
public function get(string $argument): string
{
return $this->maybe($argument)->match(
Expand All @@ -41,6 +42,7 @@ public function get(string $argument): string
/**
* @return Maybe<string>
*/
#[\NoDiscard]
public function maybe(string $argument): Maybe
{
return $this->arguments->get($argument);
Expand All @@ -49,11 +51,13 @@ public function maybe(string $argument): Maybe
/**
* @return Sequence<string>
*/
#[\NoDiscard]
public function pack(): Sequence
{
return $this->pack;
}

#[\NoDiscard]
public function contains(string $argument): bool
{
return $this->arguments->contains($argument);
Expand Down
2 changes: 2 additions & 0 deletions src/Command/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public function __construct(
/**
* @return non-empty-string
*/
#[\NoDiscard]
public function name(): string
{
return $this->name;
}

#[\NoDiscard]
public function shortDescription(): ?string
{
return $this->shortDescription;
Expand Down
3 changes: 3 additions & 0 deletions src/Command/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct(?Map $options = null)
$this->options = $options ?? Map::of();
}

#[\NoDiscard]
public function get(string $option): string
{
return $this->maybe($option)->match(
Expand All @@ -36,11 +37,13 @@ public function get(string $option): string
/**
* @return Maybe<string>
*/
#[\NoDiscard]
public function maybe(string $option): Maybe
{
return $this->options->get($option);
}

#[\NoDiscard]
public function contains(string $option): bool
{
return $this->options->contains($option);
Expand Down
15 changes: 15 additions & 0 deletions src/Command/Usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private function __construct(
*
* @param non-empty-string $name
*/
#[\NoDiscard]
public static function of(string $name): self
{
/** @var ?string */
Expand All @@ -67,6 +68,7 @@ public static function of(string $name): self
*
* @param class-string<Command> $class
*/
#[\NoDiscard]
public static function for(string $class): self
{
$refl = new \ReflectionClass($class);
Expand Down Expand Up @@ -94,6 +96,7 @@ public static function for(string $class): self
/**
* @psalm-pure
*/
#[\NoDiscard]
public static function parse(string $usage): self
{
$declaration = Str::of($usage)->trim();
Expand Down Expand Up @@ -144,6 +147,7 @@ public static function parse(string $usage): self
/**
* @param non-empty-string $name
*/
#[\NoDiscard]
public function argument(string $name): self
{
$_ = $this
Expand All @@ -168,6 +172,7 @@ public function argument(string $name): self
/**
* @param non-empty-string $name
*/
#[\NoDiscard]
public function optionalArgument(string $name): self
{
return new self(
Expand All @@ -180,6 +185,7 @@ public function optionalArgument(string $name): self
);
}

#[\NoDiscard]
public function packArguments(): self
{
return new self(
Expand All @@ -196,6 +202,7 @@ public function packArguments(): self
* @param non-empty-string $name
* @param ?non-empty-string $short
*/
#[\NoDiscard]
public function option(string $name, ?string $short = null): self
{
return new self(
Expand All @@ -212,6 +219,7 @@ public function option(string $name, ?string $short = null): self
* @param non-empty-string $name
* @param ?non-empty-string $short
*/
#[\NoDiscard]
public function flag(string $name, ?string $short = null): self
{
return new self(
Expand All @@ -224,6 +232,7 @@ public function flag(string $name, ?string $short = null): self
);
}

#[\NoDiscard]
public function withShortDescription(string $description): self
{
if (Str::of($description)->contains("\n")) {
Expand All @@ -240,6 +249,7 @@ public function withShortDescription(string $description): self
);
}

#[\NoDiscard]
public function withDescription(string $description): self
{
/** @var ?string */
Expand All @@ -262,6 +272,7 @@ public function withDescription(string $description): self
*
* @param callable(): self $load
*/
#[\NoDiscard]
public function load(callable $load): self
{
$usage = Identity::defer($load);
Expand All @@ -287,6 +298,7 @@ public function load(callable $load): self
/**
* @return non-empty-string
*/
#[\NoDiscard]
public function name(): string
{
return $this->name;
Expand Down Expand Up @@ -334,11 +346,13 @@ public function matches(string $command): bool
);
}

#[\NoDiscard]
public function shortDescription(): string
{
return $this->shortDescription ?? '';
}

#[\NoDiscard]
public function pattern(): Pattern
{
return new Pattern(
Expand All @@ -351,6 +365,7 @@ public function pattern(): Pattern
/**
* @return non-empty-string
*/
#[\NoDiscard]
public function toString(): string
{
$string = $this->name;
Expand Down
3 changes: 3 additions & 0 deletions src/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private function __construct(
/**
* @return Attempt<Environment>
*/
#[\NoDiscard]
public function __invoke(Environment $env): Attempt
{
if ($this->commands instanceof Command) {
Expand All @@ -36,6 +37,7 @@ public function __invoke(Environment $env): Attempt
return self::find($env, $this->commands);
}

#[\NoDiscard]
public static function of(Command $command, Command ...$commands): self
{
return new self(match ($commands) {
Expand All @@ -50,6 +52,7 @@ public static function of(Command $command, Command ...$commands): self
*
* @param Sequence<Command> $commands
*/
#[\NoDiscard]
public static function for(Sequence $commands): self
{
return new self($commands);
Expand Down
10 changes: 10 additions & 0 deletions src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public static function of(
);
}

#[\NoDiscard]
public function arguments(): Arguments
{
return $this->arguments;
}

#[\NoDiscard]
public function options(): Options
{
return $this->options;
Expand All @@ -56,6 +58,7 @@ public function options(): Options
*
* @return array{Attempt<Str>, self}
*/
#[\NoDiscard]
public function read(?int $length = null): array
{
[$data, $env] = $this->env->read($length);
Expand All @@ -70,6 +73,7 @@ public function read(?int $length = null): array
/**
* @return Attempt<self>
*/
#[\NoDiscard]
public function output(Str $data): Attempt
{
return $this->env->output($data)->map(
Expand All @@ -84,6 +88,7 @@ public function output(Str $data): Attempt
/**
* @return Attempt<self>
*/
#[\NoDiscard]
public function error(Str $data): Attempt
{
return $this->env->error($data)->map(
Expand All @@ -95,6 +100,7 @@ public function error(Str $data): Attempt
);
}

#[\NoDiscard]
public function interactive(): bool
{
return $this->env->interactive();
Expand All @@ -103,11 +109,13 @@ public function interactive(): bool
/**
* @return Map<string, string>
*/
#[\NoDiscard]
public function variables(): Map
{
return $this->env->variables();
}

#[\NoDiscard]
public function workingDirectory(): Path
{
return $this->env->workingDirectory();
Expand All @@ -116,6 +124,7 @@ public function workingDirectory(): Path
/**
* @param int<0, 254> $exit
*/
#[\NoDiscard]
public function exit(int $exit): self
{
return new self(
Expand All @@ -128,6 +137,7 @@ public function exit(int $exit): self
/**
* @internal
*/
#[\NoDiscard]
public function environment(): Environment
{
return $this->env;
Expand Down
10 changes: 10 additions & 0 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static function inMemory(
/**
* True if the environment running the script is an interactive terminal
*/
#[\NoDiscard]
public function interactive(): bool
{
return $this->implementation->interactive();
Expand All @@ -73,6 +74,7 @@ public function interactive(): bool
*
* @return array{Attempt<Str>, self}
*/
#[\NoDiscard]
public function read(?int $length = null): array
{
[$read, $implementation] = $this->implementation->read($length);
Expand All @@ -83,6 +85,7 @@ public function read(?int $length = null): array
/**
* @return Attempt<self>
*/
#[\NoDiscard]
public function output(Str $data): Attempt
{
return $this
Expand All @@ -94,6 +97,7 @@ public function output(Str $data): Attempt
/**
* @return Attempt<self>
*/
#[\NoDiscard]
public function error(Str $data): Attempt
{
return $this
Expand All @@ -105,6 +109,7 @@ public function error(Str $data): Attempt
/**
* @return Sequence<string>
*/
#[\NoDiscard]
public function arguments(): Sequence
{
return $this->implementation->arguments();
Expand All @@ -113,6 +118,7 @@ public function arguments(): Sequence
/**
* @return Map<string, string>
*/
#[\NoDiscard]
public function variables(): Map
{
return $this->implementation->variables();
Expand All @@ -121,6 +127,7 @@ public function variables(): Map
/**
* @param int<0, 254> $code
*/
#[\NoDiscard]
public function exit(int $code): self
{
return new self($this->implementation->exit($code));
Expand All @@ -129,11 +136,13 @@ public function exit(int $code): self
/**
* @return Maybe<ExitCode>
*/
#[\NoDiscard]
public function exitCode(): Maybe
{
return $this->implementation->exitCode();
}

#[\NoDiscard]
public function workingDirectory(): Path
{
return $this->implementation->workingDirectory();
Expand All @@ -144,6 +153,7 @@ public function workingDirectory(): Path
*
* @return Sequence<array{Str, 'output'|'error'}>
*/
#[\NoDiscard]
public function outputted(): Sequence
{
return $this->implementation->outputted();
Expand Down
2 changes: 2 additions & 0 deletions src/Environment/ExitCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public function __construct(private int $code)
/**
* @return int<0, 254>
*/
#[\NoDiscard]
public function toInt(): int
{
return $this->code;
}

#[\NoDiscard]
public function successful(): bool
{
return $this->code === 0;
Expand Down
Loading