Ubiquity commands¶
Note
This part is accessible from the webtools, so if you created your project with the -a option or with the create-project command..
Commands¶
From the webtools, activate the commands part,

or go directly to http://127.0.0.1:8090/Admin/commands
.
Command info¶
It is possible to get help on a command (which produces a result equivalent to Ubiquity help cmdName
).

Command execution¶
Clicking on the run button of a command displays a form to enter the parameters (or executes it directly if it takes none).

After entering the parameters, the execution produces a result.

Commands suite¶
Return to My commands tab: It is possible to save a sequence of commands (with stored parameters), and then execute the same sequence:
Suite creation¶
Click on the add command suite

Add the desired commands and modify the parameters:

The validation generates the suite:

Commands suite execution¶
Clicking on the run button of the suite executes the list of commands it contains:

Custom command creation¶
Click on the Create devtools command button.

Enter the characteristics of the new command:
- The command name
- The command value: name of the main argument
- The command parameters: In case of multiple parameters, use comma as separator
- The command description
- The command aliases: In case of multiple aliases, use comma as separator

Note
Custom commands are created in the app/commands folder of the project.

The generated class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | namespace commands;
use Ubiquity\devtools\cmd\commands\AbstractCustomCommand;
use Ubiquity\devtools\cmd\ConsoleFormatter;
use Ubiquity\devtools\cmd\Parameter;
class CreateArray extends AbstractCustomCommand {
protected function getValue(): string {
return 'jsonValue';
}
protected function getAliases(): array {
return array("createarray","arrayFromJson");
}
protected function getName(): string {
return 'createArray';
}
protected function getParameters(): array {
return ['f' => Parameter::create('fLongName', 'The f description.', [])];
}
protected function getExamples(): array {
return ['Sample use of createArray'=>'Ubiquity createArray jsonValue'];
}
protected function getDescription(): string {
return 'Creates an array from JSON and save to file';
}
public function run($config, $options, $what, ...$otherArgs) {
//TODO implement command behavior
echo ConsoleFormatter::showInfo('Run createArray command');
}
}
|
The CreateArray command implemented:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | namespace commands;
use Ubiquity\devtools\cmd\commands\AbstractCustomCommand;
use Ubiquity\devtools\cmd\ConsoleFormatter;
use Ubiquity\devtools\cmd\Parameter;
use Ubiquity\utils\base\UFileSystem;
class CreateArray extends AbstractCustomCommand {
protected function getValue(): string {
return 'jsonValue';
}
protected function getAliases(): array {
return array(
"createarray",
"arrayFromJson"
);
}
protected function getName(): string {
return 'createArray';
}
protected function getParameters(): array {
return [
'f' => Parameter::create('filename', 'The filename to create.', [])
];
}
protected function getExamples(): array {
return [
'Save an array in test.php' => "Ubiquity createArray \"{\\\"created\\\":true}\" -f=test.php"
];
}
protected function getDescription(): string {
return 'Creates an array from JSON and save to file';
}
public function run($config, $options, $what, ...$otherArgs) {
echo ConsoleFormatter::showInfo('Run createArray command');
$array = \json_decode($what, true);
$error = \json_last_error();
if ($error != 0) {
echo ConsoleFormatter::showMessage(\json_last_error_msg(), 'error');
} else {
$filename = self::getOption($options, 'f', 'filename');
if ($filename != null) {
UFileSystem::save($filename, "<?php\nreturn " . var_export($array, true) . ";\n");
echo ConsoleFormatter::showMessage("$filename succefully created!", 'success', 'CreateArray');
} else {
echo ConsoleFormatter::showMessage("Filename must have a value!", 'error');
}
}
}
}
|
Custom command execution¶
The new command is accessible from the devtools, as long as it is in the project:
Ubiquity help createArray

Ubiquity createArray "{\"b\":true,\"i\":5,\"s\":\"string\"}" -f=test.php
