-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/classes/cli/commands/errors/argument-missing.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Obadiah\Cli\Commands\Errors; | ||
|
||
use Obadiah\App; | ||
use Obadiah\Cli\Command; | ||
|
||
App::check(); | ||
|
||
class Argument_Missing extends Command | ||
{ | ||
/** | ||
* Executed when a Command requires an argument that is missing. | ||
* | ||
* @param string $command_name Command name. | ||
* @param string $arg_long Long form of the missing argument. | ||
* @param string|null $arg_short Optional short form of the missing argument. | ||
* @return void | ||
*/ | ||
public function __construct( | ||
public readonly string $command_name, | ||
public readonly string $arg_long, | ||
public readonly ?string $arg_short | ||
) {} | ||
|
||
/** | ||
* Output error message and exit. | ||
* | ||
* @return never | ||
*/ | ||
public function execute(): void | ||
{ | ||
App::die("Command %s requires parameter %s%s.", $this->command_name, $this->arg_long, $this->arg_short == null ? "" : " | $this->arg_short"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Obadiah\Cli\Commands\Errors; | ||
|
||
use Obadiah\App; | ||
use Obadiah\Cli\Command; | ||
|
||
App::check(); | ||
|
||
class Invalid extends Command | ||
{ | ||
/** | ||
* Executed when something goes wrong creating an instance of a command. | ||
* | ||
* @param string $command_class Command class name. | ||
* @return void | ||
*/ | ||
public function __construct( | ||
public readonly string $command_class | ||
) {} | ||
|
||
/** | ||
* Output error message and exit. | ||
* | ||
* @return never | ||
*/ | ||
public function execute(): void | ||
{ | ||
App::die("Error creating %s.", $this->command_class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Obadiah\Cli\Commands\Errors; | ||
|
||
use Obadiah\App; | ||
use Obadiah\Cli\Command; | ||
|
||
App::check(); | ||
|
||
class Unknown extends Command | ||
{ | ||
/** | ||
* Executed when a command has been called and is not mapped to an implementation class. | ||
* | ||
* @param string $command_name Command name. | ||
* @return void | ||
*/ | ||
public function __construct( | ||
public readonly string $command_name | ||
) {} | ||
|
||
/** | ||
* Output error message and exit. | ||
* | ||
* @return never | ||
*/ | ||
public function execute(): void | ||
{ | ||
App::die("Unknown command: %s.", $this->command_name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Obadiah\Cli\Commands; | ||
|
||
use Obadiah\App; | ||
use Obadiah\Cli\Argument; | ||
use Obadiah\Cli\Command; | ||
|
||
App::check(); | ||
|
||
class Hello_World extends Command | ||
{ | ||
/** | ||
* Create command. | ||
* | ||
* @param string $person The person to say hello to. | ||
* @return void | ||
*/ | ||
public function __construct( | ||
#[Argument("The name of the person to say hello to.", long: "to", required: true)] | ||
public readonly string $person | ||
) {} | ||
|
||
/** | ||
* Say hello! | ||
* | ||
* @return void | ||
*/ | ||
public function execute(): void | ||
{ | ||
App::die("Hello, $this->person!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Obadiah\Cli\Commands; | ||
|
||
use Obadiah\App; | ||
use Obadiah\Cli\Argument; | ||
use Obadiah\Cli\Command; | ||
use Obadiah\Crypto\Crypto; | ||
use SensitiveParameter; | ||
|
||
App::check(); | ||
|
||
class Password_Hash extends Command | ||
{ | ||
/** | ||
* Create command. | ||
* | ||
* @param string $password The password to hash. | ||
* @return void | ||
*/ | ||
public function __construct( | ||
#[Argument("The password to hash.", short: "p", required: true)] | ||
#[SensitiveParameter] public readonly string $password | ||
) {} | ||
|
||
/** | ||
* Output the hashed password. | ||
* | ||
* @return never | ||
*/ | ||
public function execute(): void | ||
{ | ||
App::die(Crypto::hash_password($this->password)); | ||
} | ||
} |
File renamed without changes.