Skip to content

Commit 41067a5

Browse files
committed
up: update some for add global option
1 parent 7720ce7 commit 41067a5

File tree

3 files changed

+54
-19
lines changed

3 files changed

+54
-19
lines changed

src/Application.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,16 @@ public function commands(array $commands): void
179179
*/
180180
public function registerCommands(string $namespace, string $basePath): static
181181
{
182+
$this->debugf('register commands from the namespace: %s', $namespace);
183+
182184
$length = strlen($basePath) + 1;
183185
// $iterator = Helper::directoryIterator($basePath, $this->getFileFilter());
184186
$iter = Dir::getIterator($basePath, Dir::getPhpFileFilter());
185187

186188
foreach ($iter as $file) {
187-
$class = $namespace . '\\' . substr($file->getPathName(), $length, -4);
188-
$this->addCommand($class);
189+
$subPath = substr($file->getPathName(), $length, -4);
190+
$fullClass = $namespace . '\\' . str_replace('/', '\\', $subPath);
191+
$this->addCommand($fullClass);
189192
}
190193

191194
return $this;
@@ -202,13 +205,16 @@ public function registerCommands(string $namespace, string $basePath): static
202205
*/
203206
public function registerGroups(string $namespace, string $basePath): self
204207
{
208+
$this->debugf('register groups from the namespace: %s', $namespace);
209+
205210
$length = strlen($basePath) + 1;
206211
// $iterator = Helper::directoryIterator($basePath, $this->getFileFilter());
207212
$iter = Dir::getIterator($basePath, Dir::getPhpFileFilter());
208213

209214
foreach ($iter as $file) {
210-
$class = $namespace . '\\' . substr($file->getPathName(), $length, -4);
211-
$this->addController($class);
215+
$subPath = substr($file->getPathName(), $length, -4);
216+
$fullClass = $namespace . '\\' . str_replace('/', '\\', $subPath);
217+
$this->addController($fullClass);
212218
}
213219

214220
return $this;

src/Concern/AbstractInput.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use function array_map;
1616
use function array_shift;
1717
use function basename;
18+
use function chdir;
1819
use function getcwd;
1920
use function implode;
2021
use function is_string;
@@ -194,23 +195,40 @@ public function isInteractive(): bool
194195
***********************************************************************************/
195196

196197
/**
198+
* @param bool $refresh
199+
*
197200
* @return string
198201
*/
199-
public function getPwd(): string
202+
public function getPwd(bool $refresh = false): string
200203
{
201-
if (!$this->pwd) {
204+
if (!$this->pwd || $refresh) {
202205
$this->pwd = (string)getcwd();
203206
}
204207

205208
return $this->pwd;
206209
}
207210

208211
/**
212+
* @param bool $refresh
213+
*
209214
* @return string
210215
*/
211-
public function getWorkDir(): string
216+
public function getWorkDir(bool $refresh = false): string
212217
{
213-
return $this->getPwd();
218+
return $this->getPwd($refresh);
219+
}
220+
221+
/**
222+
* @param string $workdir
223+
*
224+
* @return void
225+
*/
226+
public function chWorkDir(string $workdir): void
227+
{
228+
if ($workdir) {
229+
chdir($workdir);
230+
$this->getPwd(true);
231+
}
214232
}
215233

216234
/**

src/GlobalOption.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ class GlobalOption
4646
];
4747

4848
/**
49+
* Global options config
50+
*
4951
* @var array
5052
* @psalm-var array<string, string>
5153
*/
52-
private static array $options = [
54+
private static array $globalOptions = [
5355
'debug' => [
5456
'type' => FlagType::INT,
5557
'desc' => 'Setting the runtime log debug level, quiet 0 - crazy 5',
@@ -125,26 +127,35 @@ class GlobalOption
125127
*/
126128
public static function isExists(string $name): bool
127129
{
128-
return isset(self::KEY_MAP[$name]);
130+
return isset(self::$globalOptions[$name]);
131+
}
132+
133+
/**
134+
* @param string $name
135+
* @param array $rule
136+
*/
137+
public static function setOption(string $name, array $rule): void
138+
{
139+
self::$globalOptions[$name] = $rule;
129140
}
130141

131142
/**
132-
* @param array $options
143+
* @param array $globalOptions
133144
*/
134-
public function setOptions(array $options): void
145+
public static function setOptions(array $globalOptions): void
135146
{
136-
if ($options) {
137-
self::$options = $options;
147+
if ($globalOptions) {
148+
self::$globalOptions = $globalOptions;
138149
}
139150
}
140151

141152
/**
142-
* @param array $options
153+
* @param array $globalOptions
143154
*/
144-
public function addOptions(array $options): void
155+
public static function addOptions(array $globalOptions): void
145156
{
146-
if ($options) {
147-
self::$options = array_merge(self::$options, $options);
157+
if ($globalOptions) {
158+
self::$globalOptions = array_merge(self::$globalOptions, $globalOptions);
148159
}
149160
}
150161

@@ -153,7 +164,7 @@ public function addOptions(array $options): void
153164
*/
154165
public static function getOptions(): array
155166
{
156-
return self::$options;
167+
return self::$globalOptions;
157168
}
158169

159170
/**

0 commit comments

Comments
 (0)