-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Enhance MarkdownDescriptor #20896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Console] Enhance MarkdownDescriptor #20896
Conversation
@ogizanagi That's too many PRs on the same subject. Too much overhead for everyone. I'm going to close the 2 other ones. Let's do everything here. Let's really think about this and let's say that this one is the last one on the topic. |
No problem with that. I've cherry-picked 90dee8c so we can discuss about everything here. Last issue that should be tackled (IMHO in a dedicated PR unless you consider it a new feature rather than a bug fix for 3.2) is your comment about json & xml descriptors that should show hidden commands too. |
Tags are already included in help texts as well. Hence i chose to use getLongVersion as well. Tags are not shown anyway.. |
@ro0NL: That's not true when using shortcuts (i.e We can't do much for help texts, but this is the markdown document title. It also displays information that should not been shown for the format purpose (kernel, env, debug). |
I used github to preview, ie. the title in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Tests/Fixtures/application_2.md looks right to me |
Here is what it looks like with tags shortcuts and the Anyone may have used short closing tags in their own application and |
Fair enough. Let's add a test for it then :) edit: what if we just filter text with tags using edit2: https://3v4l.org/3DFsX |
@ro0NL : Sorry, I've missed your comment.
Which kind of test do you have in mind? IMHO it isn't worth adding a test related to this for the FrameworkBundle
If you mean just filtering the result of If you mean stripping all tags in every texts, the issue is that striptags won't preserve tags that might be legit in a description, even when escaping it, on the contrary of calling |
Maybe use short notation in the component, ie here https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Application.php#L342 That should cover.
Guess your right.. it looks bad if long version is something like
What about UX-wise, the following header;
|
Or lets forget about Lets do the XML/JSON approach 👍 and continue hardcoding Status: Reviewed |
In 7687bf5, I've added what I mentioned in #20896 (comment)
Status: Needs review |
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function write($content, $decorated = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if it's something acceptable to change the default value of an argument ($decorated
) when overriding a method for such case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default makes sense i guess. Is it really worth against changing write
calls?
I don't have more changes to bring to the descriptor. IMHO this PR is ready for a decision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -142,4 +168,17 @@ protected function describeApplication(Application $application, array $options | |||
$this->write($this->describeCommand($command)); | |||
} | |||
} | |||
|
|||
private function getApplicationTitle(Application $application) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do a new method i'd say ApplicationDescription::getTitle
for better reuseability.
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function write($content, $decorated = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default makes sense i guess. Is it really worth against changing write
calls?
@@ -102,7 +125,7 @@ protected function describeCommand(Command $command, array $options = array()) | |||
.array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) { | |||
return $carry.'* `'.$usage.'`'."\n"; | |||
}) | |||
); | |||
, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you :)
$this->write(implode("\n", array_map(function ($commandName) { | ||
return '* `'.$commandName.'`'; | ||
$this->write(implode("\n", array_map(function ($commandName) use ($description) { | ||
$anchor = '#'.strtr($description->getCommand($commandName)->getName(), array(':' => '')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do simple str_replace
here. And this can actually be $commandName
right? 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows to handle aliases. See https://github.com/symfony/symfony/pull/20896/files#diff-57586bcf27971e696e76fbcec2e17283R4 (the anchor generated for the alias)
Thank you @ogizanagi. |
This PR was squashed before being merged into the 3.3-dev branch (closes #20896). Discussion ---------- [Console] Enhance MarkdownDescriptor | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A In order to add usefulness to this descriptor, this PR allows to jump to a command description by clicking on the command name on the application summary. It's not a generic approach but IMHO a quick win that should work at least for Github flavoured markdown. The markdown format should also avoid using `Application::getLongVersion` as the markdown document title, as it may contain tags (and unnecessary information using the framework). Lastly, the markdown format is now cleaned from tags initially used for console output formatting and only keeps properly escaped ones. Commits ------- ef5b087 Do not output formatting tags 6896865 [Console] MarkdownDescriptor: Don't use getLongVersion fc2395e [Console] MarkdownDescriptor: Link to commands anchors
In order to add usefulness to this descriptor, this PR allows to jump to a command description by clicking on the command name on the application summary.
It's not a generic approach but IMHO a quick win that should work at least for Github flavoured markdown.
The markdown format should also avoid using
Application::getLongVersion
as the markdown document title, as it may contain tags (and unnecessary information using the framework).Lastly, the markdown format is now cleaned from tags initially used for console output formatting and only keeps properly escaped ones.