Skip to content

add functionality to allow hiding commands in /help command #430

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

Merged
merged 10 commits into from
Mar 12, 2017
Merged

add functionality to allow hiding commands in /help command #430

merged 10 commits into from
Mar 12, 2017

Conversation

lichtscheu
Copy link
Contributor

add protected $showInHelp var to Command.php

add public function getShowInHelp() to Command.php

add if($command->getShowInHelp()) {} to wrap single command output at HelpCommand.php

with protected $showInHelp = false; insert into the command,it is not listed with /help command.

I find this very useful, cause i have some commands i only use over cronjob and don't want this commands to show up at the help command.

@@ -69,11 +69,13 @@ public function execute()
);

foreach ($command_objs as $command) {
$text .= sprintf(
if($command->getShowInHelp()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for true and putting all the code into the if block, it's nicer to test for false and just continue with the next element.
e.g.

if (!$command->showInHelp()) {
    continue;
}

Also, remember to keep your code nice and clean, so make the indentation correct 👍

*
* @var bool
*/
protected $showInHelp = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For properties, we prefer snake case, i.e. $show_in_help

👍 for default being true

*
* @return bool
*/
public function getShowInHelp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of getShowInHelp, just use showInHelp. Similar to isEnabled, it makes it much easier to "read" the code.

Compare:

$command->getShowInHelp();

to

$command->showInHelp();

See what I mean? 😃

@lichtscheu
Copy link
Contributor Author

Thanks for the awesome review =)

@@ -69,11 +69,16 @@ public function execute()
);

foreach ($command_objs as $command) {
if($command->showInHelp()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure you tested this one, give it a go and see if this does what you want... 😉
Also, there should be a space after the if like so: if (...)

$text .= sprintf(
'/%s - %s' . PHP_EOL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation was correct, so please revert this part.

@@ -252,6 +259,16 @@ public function getName()
return $this->name;
}

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be /** for docblock to pick it up correctly.

Also, check the number of spaces and compare it with the others.
e.g.:

/**
 * There is an extra space before the *s on these lines!
 */

*/
public function showInHelp()
{
return $this->show_in_help;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent by 4 spaces, always.
What editor do you use? Make sure it has an editorconfig plugin installed.

@noplanman
Copy link
Member

@lichtscheu Also, notice that the build failed. When you click the Details button, it brings you to the Travis CI page, showing you what went wrong. It's an awesome help to make sure that everything is working properly.

Also, your changes will need some new tests, but I'll do those an PR to your branch so that you can see how they're done. If you feel like trying yourself, feel free to do so!

@noplanman noplanman merged commit 47058ef into php-telegram-bot:develop Mar 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants