1

I am writing my first symfony console apps and I would like to ask a question regarding the console outputs.

When I run a new CLI app in the console like: ./testapp then I get the following output:

Usage:
 command [options] [arguments]

Options:
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question

Available commands:
 help       Displays help for a command
 list       Lists commands

Is there a way to remove the display of this content? I want only the "Available Commands" to be visible. And is it possible to create my own groups in this display?

René Höhle
  • 26,716
  • 22
  • 73
  • 82
sesc360
  • 3,155
  • 10
  • 44
  • 86
  • That make not so much sense to remove the Options. What would you do that? ;) That are the options for your current command. – René Höhle Apr 04 '15 at 12:13
  • 1
    Well.. I do not want to remove the options itself. Only the display when calling the app. So to clean up the view so to speak – sesc360 Apr 04 '15 at 12:14
  • I don't understand your problem ;) when you call your command correctly you don't get that output then your command is executed. – René Höhle Apr 04 '15 at 12:15
  • Well there is not really a problem... :) Of course my command gets called correctly. But when I just call ./testapp I see this informational screen with the Name of the Application and the content above. and there I want to have a cleaned up display, as I only want the see the available commands section – sesc360 Apr 04 '15 at 12:19
  • I don't think that this is possible because that make really no sense. The usage description on top depends on the informations under the Usage command. But perhaps anybody here knows a solution. – René Höhle Apr 04 '15 at 12:22
  • Possible duplicate of [Symfony Console - Overwrite default options](https://stackoverflow.com/questions/45717763/symfony-console-overwrite-default-options) – Tomas Votruba Oct 27 '17 at 19:24
  • Opinion: it's possible to hide the default `help` and `list` commands with `$app->get('list')->setHidden(TRUE)`, so, it should also be possible to hide the default options. – pmiguelpinto90 Aug 23 '18 at 08:46

2 Answers2

1

As of Symfony 2.5, you can change the default command (the command that's executed when no command name was specified). See for more information: http://symfony.com/doc/current/components/console/changing_default_command.html

The Console component will always run the ListCommand when no command name is passed. In order to change the default command you just need to pass the command name to the setDefaultCommand method.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
  • But he want only the one list with available commands and don't overwrite the complete command. Ok then he have to implement that but its a bit useless ^^ to override the output is cool if you work with that output to parse them for example.. – René Höhle Apr 04 '15 at 20:52
0

(Symfony Console 4.1)

It's possible to remove the default options:

$options = $app->getDefinition()->getOptions();
unset($options['ansi']);
unset($options['no-interaction']);
unset($options['verbose']);
unset($options['help']);
unset($options['quiet']);
unset($options['version']);
unset($options['no-ansi']);
$app->getDefinition()->setOptions($options);

or just:

$app->getDefinition()->setOptions();

Options group will not show in the list command.

Although I don't know if this has any undesirable side effect.

pmiguelpinto90
  • 573
  • 9
  • 19