Updated system:* commands help doc
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Commands\System;
|
||||
|
||||
use App\Command;
|
||||
use App\Libs\Config;
|
||||
use App\Libs\Routable;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -16,8 +17,55 @@ final class EnvCommand extends Command
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$configPath = after(Config::get('path') . '/config/', ROOT_PATH);
|
||||
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Dump loaded environment variables.');
|
||||
->setDescription('Show loaded environment variables.')
|
||||
->setHelp(
|
||||
replacer(
|
||||
<<<HELP
|
||||
|
||||
This command display the environment variables that was loaded during the run of the tool.
|
||||
You can load environment variables in many ways. However, the recommended methods are:
|
||||
|
||||
<comment># Docker compose file</comment>
|
||||
|
||||
You can load environment variables via [<comment>docker-compose.yaml</comment>] file by adding them under the [<comment>environment</comment>] key.
|
||||
|
||||
<comment>## [ Example ]</comment>
|
||||
|
||||
To enable import task, do the following:
|
||||
|
||||
-------------------------------
|
||||
version: '3.3'
|
||||
services:
|
||||
watchstate:
|
||||
image: ghcr.io/arabcoders/watchstate:latest
|
||||
restart: unless-stopped
|
||||
container_name: watchstate
|
||||
<comment>environment:</comment>
|
||||
<info>- WS_CRON_IMPORT=1</info>
|
||||
-------------------------------
|
||||
|
||||
<comment># .env file</comment>
|
||||
|
||||
We automatically look for [<comment>.env</comment>] in this path [<info>{path}</info>]. The file usually
|
||||
does not exist unless you have created it.
|
||||
|
||||
The file format is simple <info>[KEY<comment>=</comment>VALUE]</info> pair per line.
|
||||
|
||||
<comment>## [ Example ]</comment>
|
||||
|
||||
To enable import task add the following line to [<comment>.env</comment>] file
|
||||
|
||||
-------------------------------
|
||||
<info>WS_CRON_IMPORT<comment>=</comment>1</info>
|
||||
-------------------------------
|
||||
|
||||
HELP,
|
||||
['path' => $configPath]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
|
||||
@@ -26,18 +26,25 @@ final class IndexCommand extends Command
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$cmdContext = trim(commandContext());
|
||||
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Ensure database has correct indexes.')
|
||||
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not commit changes.')
|
||||
->addOption('force-reindex', 'f', InputOption::VALUE_NONE, 'Drop existing indexes, and re-create them.')
|
||||
->setHelp(
|
||||
<<<HELP
|
||||
replacer(
|
||||
<<<HELP
|
||||
|
||||
This command ensure that your database has the correct indexes to speed up lookups,
|
||||
If you notice slowness in responses or sync, try running this command in [-f, --force-reindex]
|
||||
to re-create your Indexes.
|
||||
This command check the status of your database indexes, and update any missed index.
|
||||
|
||||
HELP
|
||||
To recreate your database indexes run the following command
|
||||
|
||||
{cmd} {route} --force-reindex -vvv
|
||||
|
||||
HELP,
|
||||
['cmd' => $cmdContext, 'route' => self::ROUTE]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,20 +32,22 @@ final class LogsCommand extends Command
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$defaultDate = makeDate()->format('Ymd');
|
||||
|
||||
$this->setName(self::ROUTE)
|
||||
->addOption(
|
||||
'type',
|
||||
null,
|
||||
't',
|
||||
InputOption::VALUE_REQUIRED,
|
||||
sprintf('Log type, can be [%s].', implode(', ', self::LOG_FILES)),
|
||||
self::LOG_FILES[0]
|
||||
)
|
||||
->addOption(
|
||||
'date',
|
||||
null,
|
||||
'd',
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Which log date to open. Format is [YYYYMMDD].',
|
||||
makeDate()->format('Ymd'),
|
||||
$defaultDate,
|
||||
)
|
||||
->addOption('list', null, InputOption::VALUE_NONE, 'List All log files.')
|
||||
->addOption(
|
||||
@@ -55,10 +57,68 @@ final class LogsCommand extends Command
|
||||
'Show last X number of log lines.',
|
||||
self::DEFAULT_LIMIT
|
||||
)
|
||||
->addOption('tail', 't', InputOption::VALUE_NONE, 'Tail logfile.')
|
||||
->addOption('follow', 'f', InputOption::VALUE_NONE, 'Follow log file.')
|
||||
->addOption('clear', null, InputOption::VALUE_NONE, 'Clear log file')
|
||||
->setAliases(['logs'])
|
||||
->setDescription('View current logs.');
|
||||
->setDescription('View current logs.')
|
||||
->setHelp(
|
||||
replacer(
|
||||
<<<HELP
|
||||
|
||||
This command allow you to access all recorded logs by the tool.
|
||||
|
||||
-------------------
|
||||
<comment>[ Expected Values ]</comment>
|
||||
-------------------
|
||||
|
||||
<info>type</info> expects the value to be [{files}], By Default [<comment>{defaultLog}</comment>].
|
||||
<info>date</info> expects the value to be [<comment>(number){8}</comment>]. By Default [<comment>{defaultDate}</comment>].
|
||||
<info>limit</info> expects the value to be [<comment>(number)</comment>]. By Default [<comment>{defaultLimit}</comment>].
|
||||
|
||||
-------
|
||||
<comment>[ FAQ ]</comment>
|
||||
-------
|
||||
|
||||
<comment># How to see all log files?</comment>
|
||||
|
||||
{cmd} {route} <info>--list</info>
|
||||
|
||||
<comment># How to follow log file?</comment>
|
||||
|
||||
{cmd} {route} <info>--follow</info>
|
||||
|
||||
<comment># How to clear log file?</comment>
|
||||
|
||||
You can clear log file by running this command, However clearing log file require interactive confirmation.
|
||||
|
||||
{cmd} {route} --type {defaultLog} --date {defaultDate} <info>--clear</info>
|
||||
|
||||
<comment># How to increase/decrease the returned log lines?</comment>
|
||||
|
||||
By default, we return the last [<comment>{defaultLimit}</comment>] log lines. However, you can increase/decrease
|
||||
the limit however you like by using [<info>-l, --limit</info>] flag. For example,
|
||||
|
||||
{cmd} {route} <info>--limit</info> <comment>100</comment>
|
||||
|
||||
<comment># Where log files stored?</comment>
|
||||
|
||||
By default, We store logs at [<info>{logsPath}</info>]
|
||||
|
||||
HELP,
|
||||
[
|
||||
'files' => implode(
|
||||
' or ',
|
||||
array_map(fn($val) => '<comment>' . $val . '</comment>', self::LOG_FILES)
|
||||
),
|
||||
'defaultLog' => self::LOG_FILES[0],
|
||||
'defaultDate' => $defaultDate,
|
||||
'defaultLimit' => self::DEFAULT_LIMIT,
|
||||
'cmd' => trim(commandContext()),
|
||||
'route' => self::ROUTE,
|
||||
'logsPath' => Config::get('tmpDir') . '/logs',
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +164,7 @@ final class LogsCommand extends Command
|
||||
return $this->handleClearLog($file, $input, $output);
|
||||
}
|
||||
|
||||
if ($input->getOption('tail')) {
|
||||
if ($input->getOption('follow')) {
|
||||
$p = $file->getRealPath();
|
||||
$lastPos = 0;
|
||||
|
||||
@@ -176,19 +236,20 @@ final class LogsCommand extends Command
|
||||
$isTable = $input->getOption('output') === 'table';
|
||||
|
||||
foreach (glob($path . '/*.*.log') as $file) {
|
||||
preg_match('/(\w+)\.(\d+)\.log/i', basename($file), $matches);
|
||||
preg_match('/(\w+)\.(\w+)\.log/i', basename($file), $matches);
|
||||
|
||||
$size = filesize($file);
|
||||
|
||||
$builder = [
|
||||
'type' => $matches[1],
|
||||
'date' => $matches[2],
|
||||
'type' => $matches[1] ?? '??',
|
||||
'tag' => $matches[2] ?? '??',
|
||||
'size' => $isTable ? fsize($size) : $size,
|
||||
'modified' => makeDate(filemtime($file))->format('Y-m-d H:i:s T'),
|
||||
];
|
||||
|
||||
if (!$isTable) {
|
||||
$builder['file'] = $file;
|
||||
$builder['modified'] = makeDate(filemtime($file));
|
||||
}
|
||||
|
||||
$list[] = $builder;
|
||||
|
||||
@@ -23,7 +23,15 @@ final class MaintenanceCommand extends Command
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Run maintenance tasks on database.');
|
||||
->setDescription('Run maintenance tasks on database.')
|
||||
->setHelp(
|
||||
<<<HELP
|
||||
|
||||
This command runs maintenance tasks on database to make sure the database is in optimal state.
|
||||
You do not need to run this command unless told by the team. This is done automatically on container startup.
|
||||
|
||||
HELP
|
||||
);
|
||||
}
|
||||
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
|
||||
@@ -24,15 +24,36 @@ final class MakeCommand extends Command
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Create database migration file.')
|
||||
->addArgument('filename', InputArgument::REQUIRED, 'Migration name.');
|
||||
->setDescription('Create database schema migration file.')
|
||||
->addArgument('filename', InputArgument::REQUIRED, 'Migration name.')
|
||||
->setHelp(
|
||||
replacer(
|
||||
<<<HELP
|
||||
|
||||
This command creates a migration file for database schema.
|
||||
This is mostly used for people who develop features for this tool.
|
||||
|
||||
By default, migration files stored at [<info>{migrationPath}</info>].
|
||||
|
||||
The migration file name must be in [<info>in_english</info>] without spaces.
|
||||
|
||||
HELP,
|
||||
['migrationPath' => after(realpath(__DIR__ . '/../../../migrations'), ROOT_PATH)]
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$file = $this->db->makeMigration($input->getArgument('filename'));
|
||||
|
||||
$output->writeln(sprintf('<info>Created new migration at \'%s\'.</info>', $file));
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
'<info>Created new migration at \'%s\'.</info>',
|
||||
after(realpath($file), ROOT_PATH),
|
||||
)
|
||||
);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -25,14 +25,22 @@ final class MigrationsCommand extends Command
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Run database migrations.')
|
||||
->addOption('fresh', 'f', InputOption::VALUE_NONE, 'Start migrations from start.');
|
||||
->addOption('force', 'f', InputOption::VALUE_NONE, 'Start migrations from start.')
|
||||
->setHelp(
|
||||
<<<HELP
|
||||
|
||||
This command runs database schema migrations to make sure you database is up to date.
|
||||
You do not need to run this command unless told by the team. This is done automatically on container startup.
|
||||
|
||||
HELP
|
||||
);
|
||||
}
|
||||
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$opts = [];
|
||||
|
||||
if ($input->getOption('fresh')) {
|
||||
if ($input->getOption('force')) {
|
||||
$opts['fresh'] = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,24 @@ final class PHPCommand extends Command
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Generate php config.')
|
||||
->addOption('fpm', null, InputOption::VALUE_NONE, 'Generate php-fpm config.');
|
||||
->addOption('fpm', null, InputOption::VALUE_NONE, 'Generate php-fpm config.')
|
||||
->setHelp(
|
||||
replacer(
|
||||
<<<HELP
|
||||
|
||||
This command generate expected values for [<info>php.ini</info>] and [<info>fpm</info>] pool.
|
||||
|
||||
To generate fpm values run:
|
||||
|
||||
{cmd} {route} <info>--fpm</info>
|
||||
|
||||
HELP,
|
||||
[
|
||||
'cmd' => trim(commandContext()),
|
||||
'route' => self::ROUTE,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
|
||||
@@ -28,16 +28,25 @@ final class PruneCommand extends Command
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
// -- @RELEASE remove option.
|
||||
->addOption(
|
||||
'older-than',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Unused option. Will be removed at release.',
|
||||
Config::get('logs.prune.after', '-3 DAYS')
|
||||
)
|
||||
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not take any action.')
|
||||
->setDescription('Remove automatically generated files.');
|
||||
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not perform any actions on files.')
|
||||
->setDescription('Remove automatically generated files.')
|
||||
->setHelp(
|
||||
replacer(
|
||||
<<<HELP
|
||||
|
||||
This command remove automatically generated files. like logs and backups.
|
||||
|
||||
to see what files will be removed without actually removing them. run the following command.
|
||||
|
||||
{cmd} {route} --dry-run -vvv
|
||||
|
||||
HELP,
|
||||
[
|
||||
'cmd' => trim(commandContext()),
|
||||
'route' => self::ROUTE,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
|
||||
@@ -17,7 +17,14 @@ final class RoutesCommand extends Command
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Generate commands routes.');
|
||||
->setDescription('Generate commands routes.')->setHelp(
|
||||
<<<HELP
|
||||
|
||||
This command generate the force regenerate command routes.
|
||||
You do not need to run this command unless told by the team. This is done automatically on container startup.
|
||||
|
||||
HELP
|
||||
);
|
||||
}
|
||||
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
|
||||
@@ -36,7 +36,6 @@ final class TasksCommand extends Command
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$cmdContext = trim(commandContext()) . ' ' . self::ROUTE;
|
||||
$tasksName = implode(
|
||||
', ',
|
||||
array_map(fn($val) => '<comment>' . strtoupper($val) . '</comment>',
|
||||
@@ -50,55 +49,62 @@ final class TasksCommand extends Command
|
||||
->addOption('live', null, InputOption::VALUE_NONE, 'See output in real time.')
|
||||
->setDescription('List & Run scheduled tasks.')
|
||||
->setHelp(
|
||||
<<<HELP
|
||||
replacer(
|
||||
<<<HELP
|
||||
|
||||
This command automates the runs of scheduled tasks.
|
||||
|
||||
-------
|
||||
<comment>[ FAQ ]</comment>
|
||||
-------
|
||||
|
||||
--------------------------
|
||||
<comment># How run scheduled tasks?</comment>
|
||||
--------------------------
|
||||
|
||||
To run scheduled tasks, Do the following
|
||||
|
||||
{$cmdContext} --run
|
||||
{cmd} {route} <info>--run</info>
|
||||
|
||||
---------------------------------
|
||||
<comment># How to force run specific task?</comment>
|
||||
---------------------------------
|
||||
|
||||
You have to combine both <info>[--run]</info> and <info>[--task task_name]</info>, For example:
|
||||
You have to combine both <info>[--run]</info> and <info>[--task <comment>task_name</comment>]</info>, For example:
|
||||
|
||||
{$cmdContext} <info>--run --task</info> <comment>import</comment>
|
||||
{cmd} {route} <info>--task</info> <comment>import</comment> <info>--run</info>
|
||||
|
||||
Running task in force mode, bypass the task enabled check.
|
||||
|
||||
-------------------------
|
||||
<comment># How to configure tasks?</comment>
|
||||
-------------------------
|
||||
|
||||
All Prebuilt tasks have 3 environment variables assoicated with them.
|
||||
All Prebuilt tasks have 3 environment variables associated with them.
|
||||
|
||||
## <info>WS_CRON_<comment>{TASK}</comment>:</info>
|
||||
|
||||
This environment variable control whether the task is enabled or not, it auto cast the value to bool. For example,
|
||||
to enable <comment>import</comment> task simply add new environment varaible called <info>WS_CRON_</info><comment>IMPORT</comment> with value of <info>true</info> or <info>1</info>.
|
||||
to enable <comment>import</comment> task simply add new environment variable called [<info>WS_CRON_</info><comment>IMPORT</comment>] with value of [<info>true</info>] or [<info>1</info>].
|
||||
|
||||
## <info>WS_CRON_<comment>{TASK}</comment>_AT:</info>
|
||||
|
||||
This environment variable control when the task should run, it accepts valid cron expression timer. For example,
|
||||
to run <comment>import</comment> every two hours add new environment variable called <info>WS_CRON_<comment>IMPORT</comment>_AT</info> with value of <info>0 */2 * * *</info>.
|
||||
to run <comment>import</comment> every two hours add new environment variable called [<info>WS_CRON_<comment>IMPORT</comment>_AT</info>] with value of [<info>0 */2 * * *</info>].
|
||||
|
||||
|
||||
## <info>WS_CRON_<comment>{TASK}</comment>_ARGS</info>:
|
||||
|
||||
This environment variable control the options passed to the executed command, For example to expand the information
|
||||
logged during <comment>import</comment> run, add new environment variable called <info>WS_CRON_<comment>IMPORT</comment>_ARGS</info> with value of <info>-vvv --context --trace</info>.
|
||||
Simply put, run help on the assoicated command, and you can use any <comment>Options</comment> listed there in this variable.
|
||||
logged during <comment>import</comment> run, add new environment variable called [<info>WS_CRON_<comment>IMPORT</comment>_ARGS</info>] with value of [<info>-vvv --context</info>].
|
||||
Simply put, run help on the associated command, and you can use any <comment>Options</comment> listed there in this variable.
|
||||
|
||||
-------------------------------------
|
||||
## <comment>{TASK}</comment>
|
||||
|
||||
Replace <comment>{TASK}</comment> which one of the following [ $tasksName ]
|
||||
environment variables are in ALL CAPITAL LETTERS
|
||||
Replace <comment>{TASK}</comment> tag in environment variables which one of the following [ {tasksList} ]
|
||||
environment variables are in <comment>ALL CAPITAL LETTERS</comment>.
|
||||
|
||||
HELP
|
||||
HELP,
|
||||
[
|
||||
'cmd' => trim(commandContext()),
|
||||
'route' => self::ROUTE,
|
||||
'tasksList' => $tasksName,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user