This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes.php
149 lines (143 loc) · 5.32 KB
/
notes.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Console\Controllers\ManipulatorController;
use App\Http\Controllers\GuiController;
class StimpackCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'stimpack {parameters?*}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Proxy command for stimpack-cli';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$handler = collect([
'stimpack' => "homeHandler",
'stimpack help' => "helpHandler",
'stimpack list' => "listHandler",
'stimpack run [\w-\s]+' => "runHandler",
"stimpack new [\w-]+( from [\w-\/]+)?" => "newHandler",
"stimpack open [\w-]+" => "openHandler",
// default
'.*?' => "commandNotRecognizedHandler"
])->first(function($handler, $regex) {
return preg_match('/^' . $regex . '$/', $this->fullCommand());
});
$this->$handler();
}
private function args() {
return collect($this->argument('parameters'));
}
private function fullCommand() {
return collect(["stimpack"])->concat($this->args())->implode(" ");
}
private function homeHandler() {
$logo = '
_____ __ _ __
/ ___// /_(_)___ ___ ____ ____ ______/ /__
\__ \/ __/ / __ `__ \/ __ \/ __ `/ ___/ //_/
___/ / /_/ / / / / / / /_/ / /_/ / /__/ ,<
/____/\__/_/_/ /_/ /_/ .___/\__,_/\___/_/|_|
/_/';
$this->line($logo);
$this->line("\n By Anders Jürisoo and contributors");
$this->helpHandler();
}
private function helpHandler() {
$this->table(["Command", "Hint"], [
["stimpack", "Display help"],
["stimpack park", "Install and set stimpack home to current directory."],
["stimpack new <name> [from <pack>] [in gui]", "Create a new project using your default pack or an arbitary pack. Optionally use 'in gui' to edit settings before creating."],
["stimpack new pack <name> [from <pack>]", "Create a new pack, optionally as a copy of an already existing pack."],
["stimpack open <name>", "Open an existing project in stimpack gui."],
]);
}
private function openHandler() {
// stimpack open pack
$project = $this->args()[1];
exec("xdg-open http://stimpack.test/open/" . $project);
}
private function runHandler() {
// stimpack run pack
$packName = $this->args()[1];
$packParameters = $this->args()->slice(2)->values();
$compiledManipulators = collect(json_decode(
file_get_contents(storage_path("stimpack/packs/" . $packName . ".json"))
)->compiled);
$this->info("Running pack " . $packName . "!\n");
$compiledManipulators->each(function($manipulator) {
$this->info($manipulator->name);
collect(
ManipulatorController::make()->perform($manipulator)["messages"]
)->each(function ($message) {
$this->comment(" - " .$message);
});
$this->line("");
});
}
private function newHandler() {
// stimpack new app from template
$projectName = $this->args()[1];
$packName = $this->args()[3];
$compiledManipulators = collect(json_decode(
file_get_contents(storage_path("stimpack/packs/" . $packName . ".json"))
)->compiled)->map(function($manipulator) use($projectName, $packName) {
// Reset all starters path to the project to be created
if(isset($manipulator->isStarter) && $manipulator->isStarter)
{
$manipulator->path = $projectName;
}
// Reset all context paths to the project to be created
$manipulator->context->path = $projectName;
return $manipulator;
});
$compiledManipulators->each(function($manipulator) {
$this->info($manipulator->name);
collect(
ManipulatorController::make()->perform($manipulator)["messages"]
)->each(function ($message) {
$this->comment(" - " .$message);
});
$this->line("");
});
}
private function commandNotRecognizedHandler() {
$this->error("\nStimpack could not parse parameters!");
$this->info("\nPlease confirm you are using correct syntax:\n");
$this->helpHandler();
$this->info("");
}
private function listHandler() {
$packs = (new GuiController())->localPacks();
$packs->each(function($pack) {
//$this->info($pack->name);
});
$this->table(["Local packs"],
$packs->map(function($pack) {
return [$pack->name];
})->toArray()
);
}
}