diff --git a/app/config.php b/app/config.php index 3bd2b448..b66edde2 100644 --- a/app/config.php +++ b/app/config.php @@ -67,7 +67,7 @@ use Symfony\Component\Filesystem\Filesystem; return [ - 'appName' => $_SERVER['argv'][0], + 'appName' => basename($_SERVER['argv'][0]), ExerciseDispatcher::class => factory(function (ContainerInterface $c) { $dispatcher = new ExerciseDispatcher( $c->get(RunnerFactory::class), @@ -139,6 +139,7 @@ PrintCommand::class => factory(function (ContainerInterface $c) { return new PrintCommand( + $c->get('appName'), $c->get(ExerciseRepository::class), $c->get(UserState::class), $c->get(MarkdownRenderer::class), diff --git a/src/Command/PrintCommand.php b/src/Command/PrintCommand.php index 87b444b4..05000a9a 100644 --- a/src/Command/PrintCommand.php +++ b/src/Command/PrintCommand.php @@ -13,6 +13,11 @@ */ class PrintCommand { + /** + * @var string + */ + private $appName; + /** * @var MarkdownRenderer */ @@ -34,17 +39,20 @@ class PrintCommand private $exerciseRepository; /** + * @param string $appName * @param ExerciseRepository $exerciseRepository * @param UserState $userState * @param MarkdownRenderer $markdownRenderer * @param OutputInterface $output */ public function __construct( + $appName, ExerciseRepository $exerciseRepository, UserState $userState, MarkdownRenderer $markdownRenderer, OutputInterface $output ) { + $this->appName = $appName; $this->markdownRenderer = $markdownRenderer; $this->output = $output; $this->userState = $userState; @@ -65,6 +73,8 @@ public function __invoke() $exercise = $this->exerciseRepository->findByName($currentExercise); $markDown = file_get_contents($exercise->getProblem()); - $this->output->write($this->markdownRenderer->render($markDown)); + $doc = $this->markdownRenderer->render($markDown); + $doc = str_replace('{appname}', $this->appName, $doc); + $this->output->write($doc); } } diff --git a/src/ExerciseRenderer.php b/src/ExerciseRenderer.php index 28228fae..7085df0d 100644 --- a/src/ExerciseRenderer.php +++ b/src/ExerciseRenderer.php @@ -120,7 +120,7 @@ public function __invoke(CliMenu $menu) */ private function helpLine($text, $cmd) { - $cmd = $this->color->__invoke(sprintf('php %s %s', $this->appName, $cmd))->yellow()->__toString(); + $cmd = $this->color->__invoke(sprintf('%s %s', $this->appName, $cmd))->yellow()->__toString(); return sprintf( " %s %s: %s\n", $this->color->__invoke("»")->bold()->__toString(), diff --git a/test/Command/PrintCommandTest.php b/test/Command/PrintCommandTest.php index d903e1f9..52d54d1b 100644 --- a/test/Command/PrintCommandTest.php +++ b/test/Command/PrintCommandTest.php @@ -33,7 +33,7 @@ public function testErrorIsPrintedIfNoExerciseAssigned() ->method('printError') ->with('No active exercises. Select one from the menu'); - $command = new PrintCommand($repo, $state, $renderer, $output); + $command = new PrintCommand('phpschool', $repo, $state, $renderer, $output); $this->assertSame(1, $command->__invoke()); } @@ -76,7 +76,7 @@ public function testExerciseIsPrintedIfAssigned() ->method('write') ->with('### Exercise 1'); - $command = new PrintCommand($repo, $state, $renderer, $output); + $command = new PrintCommand('phpschool', $repo, $state, $renderer, $output); $command->__invoke(); unlink($file); diff --git a/test/res/exercise-help-expected.txt b/test/res/exercise-help-expected.txt index 660ef68c..4eae9d49 100644 --- a/test/res/exercise-help-expected.txt +++ b/test/res/exercise-help-expected.txt @@ -8,9 +8,9 @@ ### Exercise Content - » To print these instructions again, run: php phpschool print - » To execute your program in a test environment, run: php phpschool run program.php - » To verify your program, run: php phpschool verify program.php - » For help run: php phpschool help + » To print these instructions again, run: phpschool print + » To execute your program in a test environment, run: phpschool run program.php + » To verify your program, run: phpschool verify program.php + » For help run: phpschool help