Skip to content

Commit

Permalink
👔 up: update fs and tool commands
Browse files Browse the repository at this point in the history
- find-exe command
  • Loading branch information
inhere committed Jan 14, 2023
1 parent ccd461e commit b5f39e8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
2 changes: 0 additions & 2 deletions app/Console/Controller/ConvertController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ protected static function commandAliases(): array
'yaml2json' => ['yml2json', 'y2j'],
'yaml2prop' => ['yml2prop', 'y2p'],
'prop2yaml' => ['prop2yml', 'p2y'],
] + [
Ts2dateCmd::getName() => Ts2dateCmd::aliases(),
];
}

Expand Down
20 changes: 10 additions & 10 deletions app/Console/Controller/Filesystem/FsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Inhere\Console\Controller;
use Inhere\Console\IO\Output;
use Inhere\Console\Util\Show;
use Inhere\Kite\Console\SubCmd\ToolCmd\FindCommand;
use Inhere\Kite\Console\SubCmd\ToolCmd\FindExeCommand;
use Toolkit\Cli\Util\Download;
use Toolkit\FsUtil\Dir;
use Toolkit\FsUtil\File;
Expand Down Expand Up @@ -50,6 +52,14 @@ protected static function commandAliases(): array
];
}

protected function subCommands(): array
{
return [
FindCommand::class,
FindExeCommand::class,
];
}

/**
* list files like linux command `ls`
*
Expand Down Expand Up @@ -106,16 +116,6 @@ public function lnCommand(Output $output): void
// $output->success('hello');
}

/**
* find file or dir
*
* @param Output $output
*/
public function findCommand(Output $output): void
{
$output->info('Please use the `kite find` command for find file,dir');
}

/**
* create directories
*
Expand Down
7 changes: 1 addition & 6 deletions app/Console/Controller/StringController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ protected static function commandAliases(): array
'process' => ['p', 'filter', 'f'],
'replace' => ['r'],
'parse' => ['fields'],
'length' => ['len', 'ln', 'count'],
] + [
RandomCommand::getName() => RandomCommand::aliases(),
ParseUrlQueryCmd::getName() => ParseUrlQueryCmd::aliases(),
HashCommand::getName() => HashCommand::aliases(),
Ts2dateCmd::getName() => Ts2dateCmd::aliases(),
'length' => ['len', 'ln', 'count'],
];
}

Expand Down
30 changes: 22 additions & 8 deletions app/Console/SubCmd/ToolCmd/FindExeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Toolkit\PFlag\FlagsParser;
use Toolkit\Sys\Sys;
use function array_merge;
use function file_exists;
use function glob;

/**
* class FindExeCommand
Expand All @@ -25,31 +29,41 @@ public static function aliases(): array
return ['find-bin'];
}

protected function configure(): void
protected function configFlags(FlagsParser $fs): void
{
$this->flags->addArgByRule('keywords', 'string;The keywords for search;true');
// $this->flags->addOpt('show', 's', 'show the tool info', 'bool');
// $this->flags->addOpt('list', 'l', 'list all can be installed tools', 'bool');
$fs->addOpt('match', 'm', 'use name for like search', 'bool');
$fs->addOpt('verbose', 'v', 'display more information', 'bool');
$fs->addArgByRule('name', 'string;The executable name for find;true');
}

protected function execute(Input $input, Output $output)
{
$fs = $this->flags;

$words = $fs->getArg('keywords');
$more = $fs->getOpt('verbose');
$like = $fs->getOpt('match');

$paths = Sys::getEnvPaths();
$output->aList($paths, "ENV PATH");
$name = $fs->getArg('name');
$more && $output->aList($paths, "ENV PATH");

$result = [];
foreach ($paths as $path) {
$matches = glob($path. "/*$words*");
if (!$like) {
if (file_exists($binFile = $path . "/$name")) {
$output->println($more ? "RESULT: $binFile" : $binFile);
return;
}
continue;
}

$matches = glob($path . "/*$name*");
if ($matches) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$result = array_merge($result, $matches);
}
}

$output->aList($result, 'RESULT');
$output->info('TODO');
}
}

0 comments on commit b5f39e8

Please sign in to comment.