Added Host connection job

parent 26816935
<?php
/**
* Created by PhpStorm.
* User: marius
* Date: 28.07.17
* Time: 18:29
*/
namespace Dev\Jobs\Tools;
use EPM\Core\Exception\UserException;
use EPM\Jobs\AbstractJob;
/**
* Class Shell
*
* @package Dev\Jobs\Tools
*/
class Shell extends AbstractJob {
/**
* @var \EPM\Factories\ShellFactory
* @inject
*/
protected $shellFactory;
/**
* @var \EPM\Factories\HostFactory
* @inject
*/
protected $hostFactory;
/**
* @var \EPM\Factories\CommandFactory
* @inject
*/
protected $commandFactory;
/**
* Execute this job
*
* @param array $parameters
*
* @return string
* @throws UserException
*/
public function run(array $parameters = []): string {
$this->shell($parameters['arguments'][0]);
return 'jobs.done';
}
/**
* @param $hostName
*
* @throws UserException
*/
public function shell($hostName): void {
global $output;
$host = $this->hostFactory->getByName($hostName);
if($host == null) {
throw new UserException('dev.shell.host.invalid');
}
$hostShell = $host->getShell()->getModel();
$hostShell->setTty(true);
try {
$output->banner('dev.jobs.tools.shell.banner', $hostShell->getLabel())->newLine();
$this->shellFactory->getByName('user')->addCommand(
$hostShell->getShellCommand()
)->execute();
} catch (\Throwable $e) {
throw new UserException($e->getMessage());
}
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ $cfg['jobs']['global'][] = 'dev.resource.encrypt';
$cfg['jobs']['global'][] = 'dev.tools.simcv';
$cfg['jobs']['global'][] = 'dev.tools.errors';
$cfg['jobs']['global'][] = 'dev.tools.template';
$cfg['jobs']['global'][] = 'dev.tools.shell';
$cfg['jobs']['dev.module.create'] = [
'options' => ['link' => false],
......@@ -42,6 +43,11 @@ $cfg['jobs']['dev.tools.template'] = [
'template' => null
]
];
$cfg['jobs']['dev.tools.shell'] = [
'arguments' => [
null
]
];
$cfg['jobs']['dev.tools.simcv'] = [
'options' => [
'keep-aspect' => false,
......
......@@ -99,6 +99,15 @@
"description": "Das zu verwendende Template"
}
}
},
"tools:shell" : {
"description": "Via Shell mit einem Server verbinden",
"options" : {
"host": {
"flags" : [ "benötigt" ],
"description": "Der zu verwendende Server"
}
}
}
}
}
......
......@@ -102,6 +102,17 @@
"description": "The template to use"
}
}
},
"tools:shell" : {
"description": "Connect to a host via shell",
"flags" : [ "global" ],
"options" : {
"host": {
"argument" : true,
"flags" : [ "required" ],
"description": "The host to use"
}
}
}
}
}
......
......@@ -10,6 +10,7 @@
"dev.jobs.tools.template.missing" : "Das Template konnte nicht gefunden werden. Probieren Sie doch Dev:Templates/Demo/Template.json",
"dev.jobs.tools.template.assistant" : "Template Assistent für %1$s",
"dev.jobs.tools.template.result" : "Resultat der Eingaben",
"dev.jobs.tools.shell.banner" : "Verbinde mit %1$s",
"dev.jobs.analyze.config.empty" : "Ihre Anfrage lieferte keine Ergebnisse",
"dev.jobs.analyze.resource.path" : "Pfad %1$s",
"dev.jobs.simcv.file" : "Pfad zu Eingabedatei",
......@@ -17,5 +18,6 @@
"e.dev.simcv.palette" : "Die Palette %1$s existiert nicht",
"e.dev.simcv.filetype" : "Unbekannter Dateityp: %1$s",
"e.dev.module.exists" : "Das Modul %1$s existiert bereits",
"e.dev.resource.invalid" : "Die Ressource %1$s konnte nicht gefunden werden"
"e.dev.resource.invalid" : "Die Ressource %1$s konnte nicht gefunden werden",
"e.dev.shell.host.invalid" : "Der Server %1$s existiert nicht"
}
\ No newline at end of file
......@@ -10,6 +10,7 @@
"dev.jobs.tools.template.missing" : "The template could not be found. try Dev:Templates/Demo/Template.json",
"dev.jobs.tools.template.assistant" : "Template Assistant for %1$s",
"dev.jobs.tools.template.result" : "Template Input Result",
"dev.jobs.tools.shell.banner" : "Connect to %1$s",
"dev.jobs.analyze.config.key" : "%1$s [%2$s]: %3$s",
"dev.jobs.analyze.config.empty" : "Your search did not match any entries",
"dev.jobs.analyze.resource.path" : "Path %1$s",
......@@ -18,5 +19,6 @@
"e.dev.simcv.palette" : "The palette %1$s does not exist",
"e.dev.simcv.filetype" : "Unknown filetype: %1$s",
"e.dev.module.exists" : "Module %1$s already exists",
"e.dev.resource.invalid" : "Resource %1$s could not be found"
"e.dev.resource.invalid" : "Resource %1$s could not be found",
"e.dev.shell.host.invalid" : "The host %1$s does not exist"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment