/**
  * @inheritDoc
  */
 public function setup(Application $application)
 {
     $this->application = $application->option('-h, --help  Show help message.')->on(Application::EVENT_BEFORE_ACTION, function (BeforeActionEvent $event) {
         if ($event->getInput()->getOption('help') == true) {
             $this->showHelpPage($event->getContext());
             $event->preventAction();
         }
     })->on(Application::EVENT_INVALID_USAGE, function (InvalidUsageEvent $event) {
         $input = $event->getInputSequence();
         $contexts = $this->application->getContexts();
         $command = [];
         while ($positional = $input->pop()) {
             $command[] = $positional;
         }
         $key = implode(' ', $command);
         if (isset($contexts[$key])) {
             $this->showHelpPage($contexts[$key]['instance']);
         } else {
             $this->showHelpPage($this->application->getRootContext());
         }
     });
 }