2024-09-24 14:20:49 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Socialbox;
|
|
|
|
|
2024-09-25 00:40:46 -04:00
|
|
|
use OptsLib\Parse;
|
|
|
|
use Socialbox\Enums\CliCommands;
|
|
|
|
|
2024-09-24 14:20:49 -04:00
|
|
|
class Program
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Socialbox main entry point
|
|
|
|
*
|
|
|
|
* @param string[] $args Command-line arguments
|
|
|
|
* @return int Exit code
|
|
|
|
*/
|
|
|
|
public static function main(array $args): int
|
|
|
|
{
|
2024-09-25 00:40:46 -04:00
|
|
|
// Parse the arguments into a more usable array format
|
|
|
|
$args = Parse::parseArgument($args);
|
|
|
|
|
|
|
|
if(isset($args['help']))
|
|
|
|
{
|
|
|
|
if($args['help'] === true)
|
|
|
|
{
|
|
|
|
return self::displayHelp();
|
|
|
|
}
|
|
|
|
|
|
|
|
$command = CliCommands::tryFrom($args['help']);
|
|
|
|
|
|
|
|
if($command === null)
|
|
|
|
{
|
|
|
|
print(sprintf("Unknown command '%s'\n", $args['help']));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
print($command->getHelpMessage());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($args[CliCommands::INITIALIZE->value]))
|
|
|
|
{
|
|
|
|
return CliCommands::INITIALIZE->handle($args);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::displayHelp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the help message for the Socialbox CLI Management Interface.
|
|
|
|
*
|
|
|
|
* This method prints out the usage instructions and a list of available commands.
|
|
|
|
*
|
|
|
|
* @return int Returns 0 upon successful display of the help message.
|
|
|
|
*/
|
|
|
|
private static function displayHelp(): int
|
|
|
|
{
|
|
|
|
print("Socialbox - CLI Management Interface\n");
|
|
|
|
print("Usage: socialbox [command] [arguments]\n\n");
|
|
|
|
print("Commands:\n");
|
|
|
|
print(" help - Displays this help message.\n");
|
|
|
|
|
|
|
|
foreach(CliCommands::cases() as $command)
|
|
|
|
{
|
|
|
|
print(sprintf(" %s - %s\n", $command->value, $command->getShortHelpMessage()));
|
|
|
|
}
|
|
|
|
|
|
|
|
print("Use 'socialbox --help=[command]' for more information about a command.\n");
|
|
|
|
|
2024-09-24 14:20:49 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|