From a598d086a842f355ea1d8b1a24eeaff4c8731322 Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Sun, 4 May 2025 20:18:40 +0200 Subject: [PATCH] chore: extend example runner to target subdirs only --- example | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/example b/example index 08dfb2e..810b868 100755 --- a/example +++ b/example @@ -3,6 +3,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\SingleCommandApplication; @@ -15,12 +16,23 @@ require_once __DIR__.'/vendor/autoload.php'; $app = (new SingleCommandApplication('LLM Chain Example Runner')) ->setDescription('Runs all LLM Chain examples in folder examples/') + ->addArgument('subdirectory', InputArgument::OPTIONAL, 'Subdirectory to run examples from, e.g. "anthropic" or "huggingface".') ->setCode(function (InputInterface $input, ConsoleOutput $output) { $io = new SymfonyStyle($input, $output); $io->title('LLM Chain Examples'); + $directory = __DIR__.'/examples'; + + if ($subdirectory = $input->getArgument('subdirectory')) { + $directory .= '/'.$subdirectory; + if (!is_dir($directory)) { + $io->error(sprintf('Subdirectory "%s" does not exist.', $subdirectory)); + return Command::FAILURE; + } + } + $examples = (new Finder()) - ->in(__DIR__.'/examples') + ->in($directory) ->name('*.php') ->sortByName() ->files();