From 2fc57bada099f36a24e837063b3fa6889cd24993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFck=20Piera?= Date: Sun, 17 Mar 2024 15:16:28 +0100 Subject: [PATCH] Rename currentDirectory into workingDirectory --- CHANGELOG.md | 4 +- doc/getting-started/context.md | 6 +-- doc/getting-started/run.md | 6 +-- .../advanced-context.md | 4 +- examples/cd.php | 2 +- examples/failure.php | 2 +- src/Context.php | 34 ++++++------ src/functions.php | 52 +++++++++---------- 8 files changed, 55 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88c088fc..2518249a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,8 @@ * Add a option `ignoreValidationErrors` on `AsTask` attribute to ignore parameters & options validation errors * Add a way to merge an application `box.json` config file used by `castor:repack`command -* Deprecate `Context::withPath()` in favor of `Context::withCurrentDirectory()` -* Deprecate `path` argument in `capture()`, `exit_code()`, `run()`, `with()` in favor of `currentDirectory` +* Deprecate `Context::withPath()` in favor of `Context::withWorkingDirectory()` +* Deprecate `path` argument in `capture()`, `exit_code()`, `run()`, `with()` in favor of `workingDirectory` ## 0.14.0 (2024-03-08) diff --git a/doc/getting-started/context.md b/doc/getting-started/context.md index 95eb501f..734d62ad 100644 --- a/doc/getting-started/context.md +++ b/doc/getting-started/context.md @@ -28,9 +28,9 @@ function foo(): void { $context = context(); - io()->writeln($context->currentDirectory); // will print the directory of the castor.php file + io()->writeln($context->workingDirectory); // will print the directory of the castor.php file - $context = $context->withCurrentDirectory('/tmp'); // will create a new context where the current directory is /tmp + $context = $context->withWorkingDirectory('/tmp'); // will create a new context where the current directory is /tmp run('pwd', context: $context); // will print "/tmp" } ``` @@ -124,7 +124,7 @@ use function Castor\run; #[AsContext(default: true, name: 'my_context')] function create_default_context(): Context { - return new Context(['foo' => 'bar'], currentDirectory: '/tmp'); + return new Context(['foo' => 'bar'], workingDirectory: '/tmp'); } #[AsTask()] diff --git a/doc/getting-started/run.md b/doc/getting-started/run.md index 3045059d..64aa731c 100644 --- a/doc/getting-started/run.md +++ b/doc/getting-started/run.md @@ -66,7 +66,7 @@ function foo(): void ## Working directory By default, Castor will execute the process in the same directory as -the `castor.php` file. You can change that by setting the `currentDirectory` +the `castor.php` file. You can change that by setting the `workingDirectory` argument. It can be either a relative or an absolute path: ```php @@ -77,8 +77,8 @@ use function Castor\run; #[AsTask()] function foo(): void { - run('pwd', currentDirectory: '../'); // run the process in the parent directory of the castor.php file - run('pwd', currentDirectory: '/tmp'); // run the process in the /tmp directory + run('pwd', workingDirectory: '../'); // run the process in the parent directory of the castor.php file + run('pwd', workingDirectory: '/tmp'); // run the process in the /tmp directory } ``` diff --git a/doc/going-further/interacting-with-castor/advanced-context.md b/doc/going-further/interacting-with-castor/advanced-context.md index f66318fb..05cfad80 100644 --- a/doc/going-further/interacting-with-castor/advanced-context.md +++ b/doc/going-further/interacting-with-castor/advanced-context.md @@ -42,7 +42,7 @@ use function Castor\run; #[AsContext(name: 'my_context')] function create_my_context(): Context { - return new Context(['foo' => 'bar'], currentDirectory: '/tmp'); + return new Context(['foo' => 'bar'], workingDirectory: '/tmp'); } #[AsTask()] @@ -71,7 +71,7 @@ use function Castor\with; #[AsContext(name: 'my_context')] function create_my_context(): Context { - return new Context(['foo' => 'bar'], currentDirectory: '/tmp'); + return new Context(['foo' => 'bar'], workingDirectory: '/tmp'); } #[AsTask()] diff --git a/examples/cd.php b/examples/cd.php index c9a9ae46..f1e3b23e 100644 --- a/examples/cd.php +++ b/examples/cd.php @@ -10,6 +10,6 @@ function directory(): void { run(['pwd']); - run(['pwd'], currentDirectory: 'src/Attribute'); + run(['pwd'], workingDirectory: 'src/Attribute'); run(['pwd']); } diff --git a/examples/failure.php b/examples/failure.php index 030d90a8..464251ae 100644 --- a/examples/failure.php +++ b/examples/failure.php @@ -9,7 +9,7 @@ #[AsTask(description: 'A failing task not authorized to fail')] function failure(): void { - run('i_do_not_exist', currentDirectory: '/tmp', pty: false); + run('i_do_not_exist', workingDirectory: '/tmp', pty: false); } #[AsTask(description: 'A failing task authorized to fail')] diff --git a/src/Context.php b/src/Context.php index da838f5b..14e0e712 100644 --- a/src/Context.php +++ b/src/Context.php @@ -4,7 +4,7 @@ class Context implements \ArrayAccess { - public readonly string $currentDirectory; + public readonly string $workingDirectory; /** * @phpstan-param ContextData $data The input parameter accepts an array or an Object @@ -14,7 +14,7 @@ class Context implements \ArrayAccess public function __construct( public readonly array $data = [], public readonly array $environment = [], - ?string $currentDirectory = null, + ?string $workingDirectory = null, public readonly bool $tty = false, public readonly bool $pty = true, public readonly ?float $timeout = null, @@ -25,7 +25,7 @@ public function __construct( // Do not use this argument, it is only used internally by the application public readonly string $name = '', ) { - $this->currentDirectory = $currentDirectory ?? PathHelper::getRoot(); + $this->workingDirectory = $workingDirectory ?? PathHelper::getRoot(); } public function __debugInfo() @@ -34,7 +34,7 @@ public function __debugInfo() 'name' => $this->name, 'data' => $this->data, 'environment' => $this->environment, - 'currentDirectory' => $this->currentDirectory, + 'workingDirectory' => $this->workingDirectory, 'tty' => $this->tty, 'pty' => $this->pty, 'timeout' => $this->timeout, @@ -67,7 +67,7 @@ public function withData(array $data, bool $keepExisting = true, bool $recursive return new self( $data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $this->timeout, @@ -85,7 +85,7 @@ public function withEnvironment(array $environment, bool $keepExisting = true): return new self( $this->data, $keepExisting ? [...$this->environment, ...$environment] : $environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $this->timeout, @@ -101,15 +101,15 @@ public function withPath(string $path): self { trigger_deprecation('castor', '0.15', 'The method "%s()" is deprecated, use "%s::withCurrentDirectory()" instead.', __METHOD__, __CLASS__); - return $this->withCurrentDirectory($path); + return $this->withWorkingDirectory($path); } - public function withCurrentDirectory(string $currentDirectory): self + public function withWorkingDirectory(string $workingDirectory): self { return new self( $this->data, $this->environment, - str_starts_with($currentDirectory, '/') ? $currentDirectory : PathHelper::realpath($this->currentDirectory . '/' . $currentDirectory), + str_starts_with($workingDirectory, '/') ? $workingDirectory : PathHelper::realpath($this->workingDirectory . '/' . $workingDirectory), $this->tty, $this->pty, $this->timeout, @@ -126,7 +126,7 @@ public function withTty(bool $tty = true): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $tty, $this->pty, $this->timeout, @@ -143,7 +143,7 @@ public function withPty(bool $pty = true): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $pty, $this->timeout, @@ -160,7 +160,7 @@ public function withTimeout(?float $timeout): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $timeout, @@ -177,7 +177,7 @@ public function withQuiet(bool $quiet = true): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $this->timeout, @@ -194,7 +194,7 @@ public function withAllowFailure(bool $allowFailure = true): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $this->timeout, @@ -211,7 +211,7 @@ public function withNotify(bool $notify = true): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $this->timeout, @@ -228,7 +228,7 @@ public function withVerbosityLevel(VerbosityLevel $verbosityLevel): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $this->timeout, @@ -245,7 +245,7 @@ public function withName(string $name): self return new self( $this->data, $this->environment, - $this->currentDirectory, + $this->workingDirectory, $this->tty, $this->pty, $this->timeout, diff --git a/src/functions.php b/src/functions.php index c303f678..abed0c6f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -113,7 +113,7 @@ function parallel(callable ...$callbacks): array function run( string|array $command, ?array $environment = null, - ?string $currentDirectory = null, + ?string $workingDirectory = null, ?bool $tty = null, ?bool $pty = null, ?float $timeout = null, @@ -130,16 +130,16 @@ function run( $context = $context->withEnvironment($environment); } - if ($currentDirectory) { - $context = $context->withCurrentDirectory($currentDirectory); + if ($workingDirectory) { + $context = $context->withWorkingDirectory($workingDirectory); if ($path) { - throw new \LogicException('You cannot use both the "path" and "currentDirectory" arguments at the same time.'); + throw new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.'); } } if ($path) { - trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "currentDirectory" instead.'); + trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "workingDirectory" instead.'); - $context = $context->withCurrentDirectory($path); + $context = $context->withWorkingDirectory($path); } if (null !== $tty) { @@ -167,9 +167,9 @@ function run( } if (\is_array($command)) { - $process = new Process($command, $context->currentDirectory, $context->environment, null, $context->timeout); + $process = new Process($command, $context->workingDirectory, $context->environment, null, $context->timeout); } else { - $process = Process::fromShellCommandline($command, $context->currentDirectory, $context->environment, null, $context->timeout); + $process = Process::fromShellCommandline($command, $context->workingDirectory, $context->environment, null, $context->timeout); } // When quiet is set, it means we want to capture the output. @@ -259,7 +259,7 @@ function run( function capture( string|array $command, ?array $environment = null, - ?string $currentDirectory = null, + ?string $workingDirectory = null, ?float $timeout = null, ?bool $allowFailure = null, ?string $onFailure = null, @@ -274,19 +274,19 @@ function capture( $allowFailure = true; } - if ($currentDirectory && $path) { - throw new \LogicException('You cannot use both the "path" and "currentDirectory" arguments at the same time.'); + if ($workingDirectory && $path) { + throw new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.'); } if ($path) { - trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "currentDirectory" instead.'); + trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "workingDirectory" instead.'); - $currentDirectory = $path; + $workingDirectory = $path; } $process = run( command: $command, environment: $environment, - currentDirectory: $currentDirectory, + workingDirectory: $workingDirectory, timeout: $timeout, allowFailure: $allowFailure, context: $context, @@ -307,25 +307,25 @@ function capture( function exit_code( string|array $command, ?array $environment = null, - ?string $currentDirectory = null, + ?string $workingDirectory = null, ?float $timeout = null, ?bool $quiet = null, ?Context $context = null, ?string $path = null, ): int { - if ($currentDirectory && $path) { - throw new \LogicException('You cannot use both the "path" and "currentDirectory" arguments at the same time.'); + if ($workingDirectory && $path) { + throw new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.'); } if ($path) { - trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "currentDirectory" instead.'); + trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "workingDirectory" instead.'); - $currentDirectory = $path; + $workingDirectory = $path; } $process = run( command: $command, environment: $environment, - currentDirectory: $currentDirectory, + workingDirectory: $workingDirectory, timeout: $timeout, allowFailure: true, context: $context, @@ -831,7 +831,7 @@ function with( callable $callback, ?array $data = null, ?array $environment = null, - ?string $currentDirectory = null, + ?string $workingDirectory = null, ?bool $tty = null, ?bool $pty = null, ?float $timeout = null, @@ -861,16 +861,16 @@ function with( $context = $context->withEnvironment($environment); } - if ($currentDirectory) { - $context = $context->withCurrentDirectory($currentDirectory); + if ($workingDirectory) { + $context = $context->withWorkingDirectory($workingDirectory); if ($path) { - throw new \LogicException('You cannot use both the "path" and "currentDirectory" arguments at the same time.'); + throw new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.'); } } if ($path) { - trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "currentDirectory" instead.'); + trigger_deprecation('castor', '0.15', 'The "path" argument is deprecated, use "workingDirectory" instead.'); - $context = $context->withCurrentDirectory($path); + $context = $context->withWorkingDirectory($path); } if (null !== $tty) {