Explorar o código

[Console] fixed synopsis when an error occurs

Fabien Potencier %!s(int64=14) %!d(string=hai) anos
pai
achega
c2e9dd27b2

+ 9 - 1
src/Symfony/Component/Console/Command/Command.php

@@ -35,6 +35,7 @@ class Command
     protected $ignoreValidationErrors;
     protected $applicationDefinitionMerged;
     protected $code;
+    protected $synopsis;
 
     /**
      * Constructor.
@@ -137,6 +138,9 @@ class Command
      */
     public function run(InputInterface $input, OutputInterface $output)
     {
+        // force the creation of the synopsis before the merge with the app definition
+        $this->getSynopsis();
+
         // add the application arguments and options
         $this->mergeApplicationDefinition();
 
@@ -431,7 +435,11 @@ class Command
      */
     public function getSynopsis()
     {
-        return sprintf('%s %s', $this->getFullName(), $this->definition->getSynopsis());
+        if (null === $this->synopsis) {
+            $this->synopsis = trim(sprintf('%s %s', $this->getFullName(), $this->definition->getSynopsis()));
+        }
+
+        return $this->synopsis;
     }
 
     /**

+ 1 - 1
tests/Symfony/Tests/Component/Console/Fixtures/application_asxml1.txt

@@ -56,7 +56,7 @@
   </options>
 </command>
     <command id="foo:bar" namespace="foo" name="bar">
-  <usage>foo:bar </usage>
+  <usage>foo:bar</usage>
   <description>The foo:bar command</description>
   <help/>
   <aliases>

+ 1 - 1
tests/Symfony/Tests/Component/Console/Fixtures/application_asxml2.txt

@@ -2,7 +2,7 @@
 <symfony>
   <commands namespace="foo">
     <command id="foo:bar" namespace="foo" name="bar">
-  <usage>foo:bar </usage>
+  <usage>foo:bar</usage>
   <description>The foo:bar command</description>
   <help/>
   <aliases>

+ 1 - 1
tests/Symfony/Tests/Component/Console/Fixtures/application_renderexception2.txt

@@ -6,6 +6,6 @@
                                       
 
 
-list [--xml] [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version] [-a|--ansi] [-n|--no-interaction] command [namespace]
+list [--xml] [namespace]
 
 

+ 1 - 1
tests/Symfony/Tests/Component/Console/Fixtures/application_renderexception3.txt

@@ -14,6 +14,6 @@
                    
 
 
-foo3:bar [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version] [-a|--ansi] [-n|--no-interaction] command
+foo3:bar
 
 

+ 1 - 1
tests/Symfony/Tests/Component/Console/Fixtures/application_run2.txt

@@ -1,5 +1,5 @@
 Usage:
- help [--xml] [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version] [-a|--ansi] [-n|--no-interaction] command [command_name]
+ help [--xml] [command_name]
 
 Aliases: ?
 Arguments:

+ 1 - 1
tests/Symfony/Tests/Component/Console/Fixtures/command_astext.txt

@@ -1,5 +1,5 @@
 <comment>Usage:</comment>
- namespace:name [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version] [-a|--ansi] [-n|--no-interaction] command
+ namespace:name
 
 <comment>Aliases:</comment> <info>name</info>
 <comment>Arguments:</comment>

+ 1 - 1
tests/Symfony/Tests/Component/Console/Fixtures/command_asxml.txt

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <command id="namespace:name" namespace="namespace" name="name">
-  <usage>namespace:name [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version] [-a|--ansi] [-n|--no-interaction] command</usage>
+  <usage>namespace:name</usage>
   <description>description</description>
   <help>help</help>
   <aliases>